QOpenGLVertexArrayObject: clean up the destructor

Calling QOpenGLContext::surface() on a non-current context will
likely return NULL, so the code path that tried to reset
the old context as current would actually fail.

Change-Id: Ibbc8da877740a596aa7dd0af8ccffb9a1877290a
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
This commit is contained in:
Giuseppe D'Angelo 2016-07-19 14:56:06 +01:00
parent e6034a4740
commit 2b9b9a38e7

View File

@ -352,9 +352,11 @@ QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject()
Q_D(QOpenGLVertexArrayObject); Q_D(QOpenGLVertexArrayObject);
QOpenGLContext *oldContext = 0; QOpenGLContext *oldContext = 0;
QSurface *oldContextSurface = 0;
QScopedPointer<QOffscreenSurface> offscreenSurface; QScopedPointer<QOffscreenSurface> offscreenSurface;
if (d->context && ctx && d->context != ctx) { if (d->context && ctx && d->context != ctx) {
oldContext = ctx; oldContext = ctx;
oldContextSurface = ctx->surface();
// Cannot just make the current surface current again with another context. // Cannot just make the current surface current again with another context.
// The format may be incompatible and some platforms (iOS) may impose // The format may be incompatible and some platforms (iOS) may impose
// restrictions on using a window with different contexts. Create an // restrictions on using a window with different contexts. Create an
@ -374,7 +376,7 @@ QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject()
destroy(); destroy();
if (oldContext) { if (oldContext) {
if (!oldContext->makeCurrent(oldContext->surface())) if (!oldContext->makeCurrent(oldContextSurface))
qWarning("QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject() failed to restore current context"); qWarning("QOpenGLVertexArrayObject::~QOpenGLVertexArrayObject() failed to restore current context");
} }
} }