Avoid using qGuiApp in QOpenGLVao::destroy()

There are convoluted cases, based on the backtrace attached
to the associated bug report, where we attempt to destroy a
QOpenGLVertexArrayObject during the destruction of Q(Gui)Application.

Just avoid accessing qGuiApp in destroy(). Rather, store it in create().

Fixes: QTBUG-75138
Pick-to: 5.15
Change-Id: If8e67301c0843cbf3a409dcf427f44c42079de2f
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
bb10
Laszlo Agocs 2020-04-21 13:43:16 +02:00
parent 1d7965fc41
commit 763752ded1
1 changed files with 5 additions and 1 deletions

View File

@ -103,6 +103,7 @@ public:
: vao(0)
, vaoFuncsType(NotSupported)
, context(nullptr)
, guiThread(nullptr)
{
}
@ -137,6 +138,7 @@ public:
} vaoFuncsType;
QOpenGLContext *context;
QThread *guiThread;
};
bool QOpenGLVertexArrayObjectPrivate::create()
@ -161,6 +163,8 @@ bool QOpenGLVertexArrayObjectPrivate::create()
context = ctx;
QObject::connect(context, SIGNAL(aboutToBeDestroyed()), q, SLOT(_q_contextAboutToBeDestroyed()));
guiThread = qGuiApp->thread();
if (ctx->isOpenGLES()) {
if (ctx->format().majorVersion() >= 3 || ctx->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) {
vaoFuncs.helper = new QOpenGLVertexArrayObjectHelper(ctx);
@ -210,7 +214,7 @@ void QOpenGLVertexArrayObjectPrivate::destroy()
// Before going through the effort of creating an offscreen surface
// check that we are on the GUI thread because otherwise many platforms
// will not able to create that offscreen surface.
if (QThread::currentThread() != qGuiApp->thread()) {
if (QThread::currentThread() != guiThread) {
ctx = nullptr;
} else {
// Cannot just make the current surface current again with another context.