From cf6a95c0ed7c1d8faef94e31cfeb33b229692d90 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 3 Mar 2004 14:15:19 +0000 Subject: [PATCH] fix problem with remove_window() removing too many windows --- panda/src/display/graphicsEngine.cxx | 6 ++++++ panda/src/display/graphicsEngine.h | 2 +- panda/src/display/graphicsOutput.I | 5 ++++- panda/src/display/graphicsOutput.cxx | 6 ++++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index 71168b86e4..5f204aa3eb 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/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(); } diff --git a/panda/src/display/graphicsEngine.h b/panda/src/display/graphicsEngine.h index 92f3ffd743..1f9f9a7da4 100644 --- a/panda/src/display/graphicsEngine.h +++ b/panda/src/display/graphicsEngine.h @@ -130,7 +130,7 @@ private: void *_data; }; - typedef ov_multiset< PT(GraphicsOutput), IndirectLess > Windows; + typedef ov_set< PT(GraphicsOutput), IndirectLess > Windows; typedef pset< PT(GraphicsStateGuardian) > GSGs; typedef pset< Callback > Callbacks; diff --git a/panda/src/display/graphicsOutput.I b/panda/src/display/graphicsOutput.I index ecb0a2a886..1a822d7c53 100644 --- a/panda/src/display/graphicsOutput.I +++ b/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; } diff --git a/panda/src/display/graphicsOutput.cxx b/panda/src/display/graphicsOutput.cxx index 8820dd9df9..f92adef186 100644 --- a/panda/src/display/graphicsOutput.cxx +++ b/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; }