From 107ac187bcc3c552217181a3b247ed5f31a9cb49 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 19 Jul 2016 13:48:33 +0100 Subject: QOpenGLDebugLogger: do not crash if deleted with the wrong GL context current Task-number: QTBUG-54799 Change-Id: Ifee3183e7944fbe266fe644628d33d0667be99a8 Reviewed-by: Friedemann Kleint Reviewed-by: Laszlo Agocs --- src/gui/opengl/qopengldebug.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/gui/opengl/qopengldebug.cpp') diff --git a/src/gui/opengl/qopengldebug.cpp b/src/gui/opengl/qopengldebug.cpp index 8b2ffb1a20..99d1e691c9 100644 --- a/src/gui/opengl/qopengldebug.cpp +++ b/src/gui/opengl/qopengldebug.cpp @@ -1500,6 +1500,12 @@ void QOpenGLDebugLogger::stopLogging() if (!d->isLogging) return; + QOpenGLContext *currentContext = QOpenGLContext::currentContext(); + if (!currentContext || currentContext != d->context) { + qWarning("QOpenGLDebugLogger::stopLogging(): attempting to stop logging with the wrong OpenGL context current"); + return; + } + d->isLogging = false; d->glDebugMessageCallback(d->oldDebugCallbackFunction, d->oldDebugCallbackParameter); -- cgit v1.2.3 From b694fe987cc423f5189102d25db1f7215a56b7f9 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 19 Jul 2016 14:57:12 +0100 Subject: QOpenGLDebugLogger: strengthen the code path in case of GL context destruction Trying to move closer to GL semantics: it is allowed to destroy a GL context at any time and that must free all of its resources. Change-Id: I3daa81d721cf26baf86a1a6435b77e3c28feb1a2 Reviewed-by: Sean Harmer --- src/gui/opengl/qopengldebug.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/gui/opengl/qopengldebug.cpp') diff --git a/src/gui/opengl/qopengldebug.cpp b/src/gui/opengl/qopengldebug.cpp index 99d1e691c9..19ceaaf815 100644 --- a/src/gui/opengl/qopengldebug.cpp +++ b/src/gui/opengl/qopengldebug.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include "qopengldebug.h" @@ -1281,8 +1282,41 @@ void QOpenGLDebugLoggerPrivate::controlDebugMessages(QOpenGLDebugMessage::Source */ void QOpenGLDebugLoggerPrivate::_q_contextAboutToBeDestroyed() { + Q_ASSERT(context); + + // Re-make our context current somehow, otherwise stopLogging will fail. + + // Save the current context and its surface in case we need to set them back + QOpenGLContext *currentContext = QOpenGLContext::currentContext(); + QSurface *currentSurface = 0; + + QScopedPointer offscreenSurface; + + if (context != currentContext) { + // Make our old context current on a temporary surface + if (currentContext) + currentSurface = currentContext->surface(); + + offscreenSurface.reset(new QOffscreenSurface); + offscreenSurface->setFormat(context->format()); + offscreenSurface->create(); + if (!context->makeCurrent(offscreenSurface.data())) + qWarning("QOpenGLDebugLoggerPrivate::_q_contextAboutToBeDestroyed(): could not make the owning GL context current for cleanup"); + } + Q_Q(QOpenGLDebugLogger); q->stopLogging(); + + if (offscreenSurface) { + // We did change the current context: set it back + if (currentContext) + currentContext->makeCurrent(currentSurface); + else + context->doneCurrent(); + } + + QObject::disconnect(context, SIGNAL(aboutToBeDestroyed()), q, SLOT(_q_contextAboutToBeDestroyed())); + context = 0; initialized = false; } -- cgit v1.2.3