Browse Source

Fix graphics buffer tracking.

aignacio_sf 17 years ago
parent
commit
f4b377e90d

+ 2 - 2
panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx

@@ -4699,11 +4699,11 @@ reset_d3d_device(D3DPRESENT_PARAMETERS *presentation_params,
     // release graphics buffer surfaces
     {
       wdxGraphicsBuffer9 *graphics_buffer;
-      list <wdxGraphicsBuffer9 *>::iterator graphics_buffer_iterator;
+      list <wdxGraphicsBuffer9 **>::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 ( );

+ 1 - 1
panda/src/dxgsg9/dxGraphicsStateGuardian9.h

@@ -362,7 +362,7 @@ protected:
 
   bool _supports_stream_offset;
 
-  list <wdxGraphicsBuffer9 *> _graphics_buffer_list;
+  list <wdxGraphicsBuffer9 **> _graphics_buffer_list;
 
   int _supports_gamma_calibration;  
 

+ 19 - 11
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;

+ 2 - 0
panda/src/dxgsg9/wdxGraphicsBuffer9.h

@@ -77,6 +77,8 @@ private:
   wdxGraphicsBuffer9 *_shared_depth_buffer;
   list <wdxGraphicsBuffer9 *> _shared_depth_buffer_list;
 
+  wdxGraphicsBuffer9 **_this;
+
 public:
   static TypeHandle get_class_type() {
     return _type_handle;