From c2aa6991d61504eb4ca7e8f27269686d9a47d6fb Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 23 Jan 2015 13:22:31 +0100 Subject: [PATCH] Fix glObjectLabel error, fix crash on shutdown with pstats-gpu-timing --- panda/src/display/graphicsStateGuardian.cxx | 7 ++++++ panda/src/glstuff/glGraphicsBuffer_src.cxx | 25 ++++++++++--------- .../glstuff/glGraphicsStateGuardian_src.cxx | 6 ++--- panda/src/glstuff/glTimerQueryContext_src.cxx | 11 +++++--- panda/src/glstuff/glTimerQueryContext_src.h | 2 +- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 2ebbad8420..9760387a48 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/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 } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/glstuff/glGraphicsBuffer_src.cxx b/panda/src/glstuff/glGraphicsBuffer_src.cxx index 038bb6b8ef..3d989401a1 100644 --- a/panda/src/glstuff/glGraphicsBuffer_src.cxx +++ b/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); diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index ed0af995b8..f0b42026d0 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/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; diff --git a/panda/src/glstuff/glTimerQueryContext_src.cxx b/panda/src/glstuff/glTimerQueryContext_src.cxx index 59c5f874a8..29fbe53f5a 100644 --- a/panda/src/glstuff/glTimerQueryContext_src.cxx +++ b/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; + } } } diff --git a/panda/src/glstuff/glTimerQueryContext_src.h b/panda/src/glstuff/glTimerQueryContext_src.h index ce4248ffd1..aeff8b1b50 100644 --- a/panda/src/glstuff/glTimerQueryContext_src.h +++ b/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() {