Skip to content

Commit

Permalink
Disconnect all signals from the QOpenGLContext
Browse files Browse the repository at this point in the history
The call stack when this assert happens indicates that there are more signals to be disconnected from the object. Crash is fixed by disconnecting all signals.

Assert seen in debug build:

ASSERT failure in caf::Viewer: "Called object is not of the correct type (class destructor may have already run)", file C:\Qt\6.6.3\msvc2019_64\include\QtCore/qobjectdefs_impl.h, line 130
  • Loading branch information
magnesj committed Oct 25, 2024
1 parent 47d4d90 commit 2b1af2b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Fwk/VizFwk/LibGuiQt/cvfqtOpenGLWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,11 @@ OpenGLWidget::~OpenGLWidget()

if (m_initializationState == IS_INITIALIZED)
{
// Make sure we disconnect from the aboutToBeDestroyed signal since after this destructor has been
// called, our object is dangling and the call to the slot will cause a crash
QOpenGLContext* myQtOpenGLContext = context();
if (myQtOpenGLContext)
if (QOpenGLContext* myQtOpenGLContext = context())
{
disconnect(myQtOpenGLContext, &QOpenGLContext::aboutToBeDestroyed, this, &OpenGLWidget::qtOpenGLContextAboutToBeDestroyed);
// Make sure we disconnect from the all signals since after this destructor has been
// called, our object is dangling and the call to any of the slots will cause a crash
myQtOpenGLContext->disconnect();
}
}

Expand Down

0 comments on commit 2b1af2b

Please sign in to comment.