diff --git a/src/Gui/Quarter/QuarterWidget.cpp b/src/Gui/Quarter/QuarterWidget.cpp index e93ef5dbda..5c9f827068 100644 --- a/src/Gui/Quarter/QuarterWidget.cpp +++ b/src/Gui/Quarter/QuarterWidget.cpp @@ -62,6 +62,7 @@ #include #include #include +#include #include #include @@ -158,11 +159,46 @@ public: //surfaceFormat.setMajorVersion(3); //surfaceFormat.setMinorVersion(2); //surfaceFormat.setProfile(QSurfaceFormat::CoreProfile); -#if defined (_DEBUG) && 1 +#if defined (_DEBUG) && 0 surfaceFormat.setOption(QSurfaceFormat::DebugContext); #endif setFormat(surfaceFormat); } + void initializeGL() + { +#if defined (_DEBUG) && 0 + QOpenGLContext *context = QOpenGLContext::currentContext(); + if (context && context->hasExtension(QByteArrayLiteral("GL_KHR_debug"))) { + QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this); + connect(logger, &QOpenGLDebugLogger::messageLogged, this, &CustomGLWidget::handleLoggedMessage); + + if (logger->initialize()) + logger->startLogging(QOpenGLDebugLogger::SynchronousLogging); + } +#endif + } + bool event(QEvent *e) + { + // If a debug logger is activated then Qt's default implementation + // first releases the context before stopping the logger. However, + // the logger needs the active context and thus crashes because it's + // null. + if (e->type() == QEvent::WindowChangeInternal) { + if (!qApp->testAttribute(Qt::AA_ShareOpenGLContexts)) { + QOpenGLDebugLogger* logger = this->findChild(); + if (logger) { + logger->stopLogging(); + delete logger; + } + } + } + + return QOpenGLWidget::event(e); + } + void handleLoggedMessage(const QOpenGLDebugMessage &message) + { + qDebug() << message; + } }; #else class CustomGLWidget : public QGLWidget {