From f4b377e90daec25d85ed244048161d9acc2dc04c Mon Sep 17 00:00:00 2001 From: aignacio_sf <> Date: Thu, 8 Jan 2009 22:01:46 +0000 Subject: [PATCH] Fix graphics buffer tracking. --- panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 4 +-- panda/src/dxgsg9/dxGraphicsStateGuardian9.h | 2 +- panda/src/dxgsg9/wdxGraphicsBuffer9.cxx | 30 ++++++++++++------- panda/src/dxgsg9/wdxGraphicsBuffer9.h | 2 ++ 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index c04c491708..34bb3aaeb3 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -4699,11 +4699,11 @@ reset_d3d_device(D3DPRESENT_PARAMETERS *presentation_params, // release graphics buffer surfaces { wdxGraphicsBuffer9 *graphics_buffer; - list ::iterator graphics_buffer_iterator; + list ::iterator graphics_buffer_iterator; for (graphics_buffer_iterator = _graphics_buffer_list.begin( ); graphics_buffer_iterator != _graphics_buffer_list.end( ); graphics_buffer_iterator++) { - graphics_buffer = (*graphics_buffer_iterator); + graphics_buffer = **graphics_buffer_iterator; if (graphics_buffer -> _color_backing_store) { graphics_buffer -> _color_backing_store -> Release ( ); diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.h b/panda/src/dxgsg9/dxGraphicsStateGuardian9.h index b12c586d3a..16cb936130 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.h +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.h @@ -362,7 +362,7 @@ protected: bool _supports_stream_offset; - list _graphics_buffer_list; + list _graphics_buffer_list; int _supports_gamma_calibration; diff --git a/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx b/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx index a82c010714..532c494a32 100644 --- a/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx +++ b/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx @@ -52,13 +52,20 @@ wdxGraphicsBuffer9(GraphicsPipe *pipe, _shared_depth_buffer = 0; _debug = 0; + _this = 0; + + if (_debug) { + cout << "+++++ wdxGraphicsBuffer9 constructor " << this << " " << this -> get_name ( ) << "\n"; + } if (_gsg) { // save to GSG list to handle device lost issues DXGraphicsStateGuardian9 *dxgsg; dxgsg = DCAST (DXGraphicsStateGuardian9, _gsg); - dxgsg -> _graphics_buffer_list.push_back(this); + _this = new (wdxGraphicsBuffer9 *); + *_this = this; + dxgsg -> _graphics_buffer_list.push_back(_this); } } @@ -70,12 +77,21 @@ wdxGraphicsBuffer9(GraphicsPipe *pipe, wdxGraphicsBuffer9:: ~wdxGraphicsBuffer9() { + if (_debug) { + cout << "----- wdxGraphicsBuffer9 destructor " << this << " " << this -> get_name ( ) << "\n"; + } + if (_gsg) { // remove from GSG list DXGraphicsStateGuardian9 *dxgsg; dxgsg = DCAST (DXGraphicsStateGuardian9, _gsg); - dxgsg -> _graphics_buffer_list.remove(this); + if (_this) { + dxgsg -> _graphics_buffer_list.remove(_this); + } + _this = 0; + _gsg.clear(); + _gsg = 0; } // unshare shared depth buffer if any @@ -96,10 +112,6 @@ wdxGraphicsBuffer9:: graphics_buffer_iterator = _shared_depth_buffer_list.begin( ); } } - - if (_debug) { - printf ("wdxGraphicsBuffer9 destructor \n"); - } this -> close_buffer ( ); } @@ -480,7 +492,7 @@ rebuild_bitplanes() { RenderTexturePlane plane = get_texture_plane(i); if (_debug) { - printf ("i = %d, RenderTexturePlane = %d \n", i, plane); +// printf ("i = %d, RenderTexturePlane = %d \n", i, plane); } switch (plane) { @@ -706,10 +718,6 @@ process_events() { void wdxGraphicsBuffer9:: close_buffer() { - if (_gsg != (GraphicsStateGuardian *)NULL) { - _gsg.clear(); - } - if (_color_backing_store) { _color_backing_store->Release(); _color_backing_store = NULL; diff --git a/panda/src/dxgsg9/wdxGraphicsBuffer9.h b/panda/src/dxgsg9/wdxGraphicsBuffer9.h index f18e0132ab..9392cace07 100644 --- a/panda/src/dxgsg9/wdxGraphicsBuffer9.h +++ b/panda/src/dxgsg9/wdxGraphicsBuffer9.h @@ -77,6 +77,8 @@ private: wdxGraphicsBuffer9 *_shared_depth_buffer; list _shared_depth_buffer_list; + wdxGraphicsBuffer9 **_this; + public: static TypeHandle get_class_type() { return _type_handle;