From ed7845098f59e5d4df7af681bc15777c0e4ca1d3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A4=C3=A4tt=C3=A4=20Antti?=
 <antti.maatta@theqtcompany.com>
Date: Mon, 9 May 2016 12:58:38 +0300
Subject: [PATCH] Fix threading issue in creating static opengl context

Add mutex lock for static opengl context creation.

Task-number: QTBUG-53202
Change-Id: Iba22339776ec8885efd82b13ae56f6781a426f4b
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
---
 src/plugins/platforms/windows/qwindowsintegration.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp
index 3966a4cd77b..968ef7bd3b2 100644
--- a/src/plugins/platforms/windows/qwindowsintegration.cpp
+++ b/src/plugins/platforms/windows/qwindowsintegration.cpp
@@ -139,7 +139,8 @@ struct QWindowsIntegrationPrivate
 #  endif
 #endif
 #ifndef QT_NO_OPENGL
-    QSharedPointer<QWindowsStaticOpenGLContext> m_staticOpenGLContext;
+    QMutex m_staticContextLock;
+    QScopedPointer<QWindowsStaticOpenGLContext> m_staticOpenGLContext;
 #endif // QT_NO_OPENGL
     QScopedPointer<QPlatformInputContext> m_inputContext;
 #ifndef QT_NO_ACCESSIBILITY
@@ -435,8 +436,9 @@ QWindowsStaticOpenGLContext *QWindowsIntegration::staticOpenGLContext()
     if (!integration)
         return 0;
     QWindowsIntegrationPrivate *d = integration->d.data();
+    QMutexLocker lock(&d->m_staticContextLock);
     if (d->m_staticOpenGLContext.isNull())
-        d->m_staticOpenGLContext = QSharedPointer<QWindowsStaticOpenGLContext>(QWindowsStaticOpenGLContext::create());
+        d->m_staticOpenGLContext.reset(QWindowsStaticOpenGLContext::create());
     return d->m_staticOpenGLContext.data();
 }
 #endif // !QT_NO_OPENGL
-- 
GitLab