Sanitize the order of things in QOpenGLContext destroy()

Amends e08fe78b2335046934abae970e59fe0156178b95 (in a way).

While touching this function in the other patch, it becomes
obvious that the order in which things are cleaned up and
invalidated is somewhat odd: the native context is in fact
gone _before_ invoking helper callbacks or tearing down the
OpenGL API wrappers. This only works because likely nothing
relies on the context still being usable when destroying
those objects and when the texture/vao helper callbacks
run.

Reorder this to: 1. emit the about-to signal 2. invoke
callbacks and null out helpers 3. destroy the function
resolvers 4. only then start tearing down the platform
(and so the underlying native) context objects.

Pick-to: 6.5
Change-Id: I9067463b8f6ce1f656129594c347c1428439ca5e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
This commit is contained in:
Laszlo Agocs 2022-12-13 12:18:22 +01:00
parent f766e60519
commit f045ef4ab6

View File

@ -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;
}
/*!