[Interest] Confused about GL context sharing

Matthew Woehlke mwoehlke.floss at gmail.com
Thu Mar 28 19:16:21 CET 2019

Let's say I have a QOpenGLWidget in a dock widget. Every time I dock or
undock the dock widget, the GL widget gets a new context.

I would like to use context sharing so that I only need to create my GL
resources (shaders, textures, buffers) once, and reuse them as the
widget is docked and undocked.

Well... it seems to be working with buffers and shaders... but if I try
to "reuse" textures (i.e. not destroy and recreate them when the context
"changes"), my application crashes:

= Invalid read of size 8
=    at 0x5990F94: glBindTexture (qopenglfunctions.h:623)
=    by 0x5990F94: bind (qopengltexture.cpp:247)
=    by 0x5990F94: QOpenGLTexture::bind() (qopengltexture.cpp:2474)
=  Address 0x1a5f5fe0 is 0 bytes inside a block of size 8 free'd
=    at 0x483A0D6: operator delete(void*, unsigned long)
=    by 0x570224F: QOpenGLContext::destroy() (qopenglcontext.cpp:655)

Am I missing something? Is this not supported? TBH, it feels a little
buggy; AFAICT, the QOpenGLTexture retains a copy of the QOpenGLFunctions
from the context which created it, which is *unique* to that context
rather than being shared between shared contexts... which all seems a
little bit dodgy.

(Note: I am using Qt::AA_ShareOpenGLContexts...)


More information about the Interest mailing list