Browse Source

Fix glObjectLabel error, fix crash on shutdown with pstats-gpu-timing

rdb 11 years ago
parent
commit
c2aa6991d6

+ 7 - 0
panda/src/display/graphicsStateGuardian.cxx

@@ -2732,6 +2732,13 @@ close_gsg() {
   Thread *current_thread = Thread::get_current_thread();
   _prepared_objects->begin_frame(this, current_thread);
   _prepared_objects->end_frame(current_thread);
+
+  // We have to clear the list of timer queries, though, otherwise
+  // their destructors will cause a crash when they try to access
+  // the GSG object.
+#ifdef DO_PSTATS
+  _pending_timer_queries.clear();
+#endif
 }
 
 ////////////////////////////////////////////////////////////////////

+ 13 - 12
panda/src/glstuff/glGraphicsBuffer_src.cxx

@@ -445,18 +445,6 @@ rebuild_bitplanes() {
     if (_fbo[layer] == 0) {
       glgsg->_glGenFramebuffers(1, &_fbo[layer]);
 
-#ifndef OPENGLES
-      if (glgsg->_use_object_labels) {
-        if (num_fbos > 1) {
-          GLchar name[128];
-          GLsizei len = snprintf(name, 128, "%s[%d]", _name.c_str(), layer);
-          glgsg->_glObjectLabel(GL_FRAMEBUFFER, _fbo[layer], len, name);
-        } else {
-          glgsg->_glObjectLabel(GL_FRAMEBUFFER, _fbo[layer], _name.size(), _name.data());
-        }
-      }
-#endif
-
       if (_fbo[layer] == 0) {
         report_my_gl_errors();
         return;
@@ -464,6 +452,19 @@ rebuild_bitplanes() {
     }
     glgsg->bind_fbo(_fbo[layer]);
 
+#ifndef OPENGLES
+    if (glgsg->_use_object_labels) {
+      // Assign a label for OpenGL to use when displaying debug messages.
+      if (num_fbos > 1) {
+        GLchar name[128];
+        GLsizei len = snprintf(name, 128, "%s[%d]", _name.c_str(), layer);
+        glgsg->_glObjectLabel(GL_FRAMEBUFFER, _fbo[layer], len, name);
+      } else {
+        glgsg->_glObjectLabel(GL_FRAMEBUFFER, _fbo[layer], _name.size(), _name.data());
+      }
+    }
+#endif
+
     // For all slots, update the slot.
     if (_use_depth_stencil) {
       bind_slot(layer, rb_resize, attach, RTP_depth_stencil, GL_DEPTH_ATTACHMENT_EXT);

+ 3 - 3
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -5122,6 +5122,9 @@ issue_timer_query(int pstats_index) {
     }
   }
 
+  // Issue the timestamp query.
+  _glQueryCounter(query->_index, GL_TIMESTAMP);
+
   if (_use_object_labels) {
     // Assign a label to it based on the PStatCollector name.
     const PStatClient *client = PStatClient::get_global_pstats();
@@ -5129,9 +5132,6 @@ issue_timer_query(int pstats_index) {
     _glObjectLabel(GL_QUERY, query->_index, name.size(), name.data());
   }
 
-  // Issue the timestamp query.
-  _glQueryCounter(query->_index, GL_TIMESTAMP);
-
   _pending_timer_queries.push_back((TimerQueryContext *)query);
 
   return (TimerQueryContext *)query;

+ 8 - 3
panda/src/glstuff/glTimerQueryContext_src.cxx

@@ -30,9 +30,14 @@ CLP(TimerQueryContext)::
 ~CLP(TimerQueryContext)() {
   if (_index != 0) {
     // Tell the GSG to recycle this index when it gets around to it.
-    LightMutexHolder holder(_glgsg->_lock);
-    _glgsg->_deleted_queries.push_back(_index);
-    _index = 0;
+    // If it has already shut down, though, too bad.  This means we
+    // never get to free this index, but presumably the app is
+    // already shutting down anyway.
+    if (!_glgsg.was_deleted()) {
+      LightMutexHolder holder(_glgsg->_lock);
+      _glgsg->_deleted_queries.push_back(_index);
+      _index = 0;
+    }
   }
 }
 

+ 1 - 1
panda/src/glstuff/glTimerQueryContext_src.h

@@ -42,7 +42,7 @@ public:
   virtual double get_timestamp() const;
 
   GLuint _index;
-  CLP(GraphicsStateGuardian) *_glgsg;
+  WPT(CLP(GraphicsStateGuardian)) _glgsg;
 
 public:
   static TypeHandle get_class_type() {