Browse Source

fix problem with remove_window() removing too many windows

David Rose 22 years ago
parent
commit
cf6a95c0ed

+ 6 - 0
panda/src/display/graphicsEngine.cxx

@@ -359,6 +359,9 @@ remove_window(GraphicsOutput *window) {
   size_t count;
   {
     MutexHolder holder(_lock);
+    if (!_windows_sorted) {
+      do_resort_windows();
+    }
     count = _windows.erase(ptwin);
   }
   if (count == 0) {
@@ -367,6 +370,8 @@ remove_window(GraphicsOutput *window) {
   }
 
   do_remove_window(window);
+
+  nassertr(count == 1, true);
   return true;
 }
 
@@ -1167,6 +1172,7 @@ do_resort_windows() {
     RenderThread *thread = (*ti).second;
     thread->resort_windows();
   }
+
   _windows.sort();
 }
 

+ 1 - 1
panda/src/display/graphicsEngine.h

@@ -130,7 +130,7 @@ private:
     void *_data;
   };
 
-  typedef ov_multiset< PT(GraphicsOutput), IndirectLess<GraphicsOutput> > Windows;
+  typedef ov_set< PT(GraphicsOutput), IndirectLess<GraphicsOutput> > Windows;
   typedef pset< PT(GraphicsStateGuardian) > GSGs;
   typedef pset< Callback > Callbacks;
 

+ 4 - 1
panda/src/display/graphicsOutput.I

@@ -264,7 +264,10 @@ needs_context() const {
 ////////////////////////////////////////////////////////////////////
 INLINE bool GraphicsOutput::
 operator < (const GraphicsOutput &other) const {
-  return _sort < other._sort;
+  if (_sort != other._sort) {
+    return _sort < other._sort;
+  }
+  return this < &other;
 }
 
 

+ 4 - 2
panda/src/display/graphicsOutput.cxx

@@ -373,7 +373,8 @@ make_texture_buffer(const string &name, int x_size, int y_size) {
           }
 
           // No good; delete the buffer and keep trying.
-          engine->remove_window(buffer);
+          bool removed = engine->remove_window(buffer);
+          nassertr(removed, NULL);
           buffer = (GraphicsOutput *)NULL;
         }
       }
@@ -390,7 +391,8 @@ make_texture_buffer(const string &name, int x_size, int y_size) {
       return buffer;
     }
     
-    engine->remove_window(buffer);
+    bool removed = engine->remove_window(buffer);
+    nassertr(removed, NULL);
     buffer = (GraphicsOutput *)NULL;
   }