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 <giuseppe.dangelo@kdab.com>
This commit is contained in:
Tor Arne Vestbø 2024-05-30 11:40:54 +02:00
parent 3c9bb0daaf
commit 8f6b27fdee

View File

@ -243,7 +243,7 @@ public:
QOpenGLEngineShaderManager* shaderManager;
QOpenGLPaintDevice* device;
int width, height;
QOpenGLContext *ctx;
QPointer<QOpenGLContext> ctx;
EngineMode mode;
QFontEngine::GlyphFormat glyphCacheFormat;