From 8f6b27fdeef4f45d70c7bc93f7393f58f5ddeb16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 30 May 2024 11:40:54 +0200 Subject: [PATCH] QOpenGL2PaintEngineEx: Store context via QPointer The QOpenGLBuffers used by QOpenGL2PaintEngineEx are tied to a specific share group on creation, via QOpenGLSharedResourceGuard. If QOpenGL2PaintEngineEx is later used with a recreated QOpenGLContext, that happens to live at the same address as the previous one, we will fail to detect that the context has changed by using a naked pointer comparison (ABA problem). If the share group of the new context is different, this will cause problems down the line in QOpenGLBuffers::bind(). This scenario has been observed on Android, where the context created in QOpenGLWidgetPrivate::initialize() ends up with the same address, but then adopts a new share context from RHI, because the widget has been moved to a different top level window. To remedy this, we store the QOpenGL2PaintEngineEx's cached context via a QPointer, so that we pick up the B state of ABA (null), and correctly throw away the old buffers in QOpenGL2PaintEngineEx::begin. Pick-to: 6.7 Change-Id: I5c221a37fd95f846d96e72509bba54f3d10fee3a Reviewed-by: Giuseppe D'Angelo --- src/opengl/qopenglpaintengine_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opengl/qopenglpaintengine_p.h b/src/opengl/qopenglpaintengine_p.h index 40ed7fe6099..df407444bef 100644 --- a/src/opengl/qopenglpaintengine_p.h +++ b/src/opengl/qopenglpaintengine_p.h @@ -243,7 +243,7 @@ public: QOpenGLEngineShaderManager* shaderManager; QOpenGLPaintDevice* device; int width, height; - QOpenGLContext *ctx; + QPointer ctx; EngineMode mode; QFontEngine::GlyphFormat glyphCacheFormat;