diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index 49ba5eea163..4a9d62829f7 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -403,18 +403,13 @@ void QOpenGLContextPrivate::adopt(QPlatformOpenGLContext *context) void QOpenGLContext::destroy() { Q_D(QOpenGLContext); + + // Notify that the native context and the QPlatformOpenGLContext are going + // to go away. if (d->platformGLContext) emit aboutToBeDestroyed(); - if (QOpenGLContext::currentContext() == this) - doneCurrent(); - if (d->shareGroup) - d->shareGroup->d_func()->removeContext(this); - d->shareGroup = nullptr; - delete d->platformGLContext; - d->platformGLContext = nullptr; - delete d->functions; - d->functions = nullptr; + // Invoke callbacks for helpers and invalidate. if (d->textureFunctionsDestroyCallback) { d->textureFunctionsDestroyCallback(); d->textureFunctionsDestroyCallback = nullptr; @@ -427,6 +422,25 @@ void QOpenGLContext::destroy() d->vaoHelperDestroyCallback = nullptr; } d->vaoHelper = nullptr; + + // Tear down function wrappers. + delete d->versionFunctions; + d->versionFunctions = nullptr; + + delete d->functions; + d->functions = nullptr; + + // Clean up and destroy the native context machinery. + if (QOpenGLContext::currentContext() == this) + doneCurrent(); + + if (d->shareGroup) + d->shareGroup->d_func()->removeContext(this); + + d->shareGroup = nullptr; + + delete d->platformGLContext; + d->platformGLContext = nullptr; } /*!