Fix race-condition crash on shut-down in QtWebEngine

If a QQuickWidget is somehow deleted below a QApplication post-routine
it may end up being deleted after QQuickRenderControlPrivate::cleanup(),
which means its QSGContext is deleted.

Change-Id: I396d236f997b7b68a96f8fdddd7d6c3fe31c10b0
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
Allan Sandfeld Jensen 2016-08-19 14:42:31 +02:00 committed by Allan Sandfeld Jensen
parent 863a76281c
commit b8f145547e
2 changed files with 7 additions and 2 deletions

View File

@ -139,7 +139,8 @@ public Q_SLOTS:
void textureFactoryDestroyed(QObject *o);
protected:
QSGContext *m_sg;
// Hold m_sg with QPointer in the rare case it gets deleted before us.
QPointer<QSGContext> m_sg;
QMutex m_mutex;
QHash<QQuickTextureFactory *, QSGTexture *> m_textures;

View File

@ -70,6 +70,9 @@ QSGDefaultRenderContext::QSGDefaultRenderContext(QSGContext *context)
*/
void QSGDefaultRenderContext::initialize(void *context)
{
if (!m_sg)
return;
QOpenGLContext *openglContext = static_cast<QOpenGLContext *>(context);
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
@ -163,7 +166,8 @@ void QSGDefaultRenderContext::invalidate()
m_gl->setProperty(QSG_RENDERCONTEXT_PROPERTY, QVariant());
m_gl = 0;
m_sg->renderContextInvalidated(this);
if (m_sg)
m_sg->renderContextInvalidated(this);
emit invalidated();
}