diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2016-07-19 14:57:12 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2016-07-27 05:13:02 +0000 |
commit | b694fe987cc423f5189102d25db1f7215a56b7f9 (patch) | |
tree | ddfe2ba984be5d652fe500f6695040959db98fa4 /src | |
parent | 65bad0d0f4e2ac14e7f439659c500c1d2c6817bc (diff) |
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 <sean.harmer@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/opengl/qopengldebug.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
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 <QtCore/qvarlengtharray.h> #include <QtGui/qopengl.h> #include <QtGui/qopenglfunctions.h> +#include <QtGui/qoffscreensurface.h> #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<QOffscreenSurface> 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; } |