summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2022-12-13 12:18:22 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2023-01-24 16:01:05 +0100
commitf045ef4ab6f72b2024119d15da8476a26e3b2242 (patch)
tree5587a8fa34fb08781dc06019a1909201c875c48c
parentf766e6051904f6755753d7d604fa8f19dbebb81b (diff)
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>
-rw-r--r--src/gui/kernel/qopenglcontext.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp
index 49ba5eea16..4a9d62829f 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;
}
/*!