Handle context lost in the Windows render loop
authorLaszlo Agocs <laszlo.agocs@digia.com>
Mon, 12 Jan 2015 16:34:42 +0000 (17:34 +0100)
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>
Tue, 3 Feb 2015 14:05:30 +0000 (14:05 +0000)
With ANGLE (which always uses this loop) EGL_CONTEXT_LOST
may happen quite often, depending on various factors.

It is therefore good to handle this by tearing down and
reinitializing the scenegraph.

Task-number: QTBUG-43263
Change-Id: I8e985e001f46865ccd814255f39add58fe2a737a
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
src/quick/scenegraph/qsgwindowsrenderloop.cpp

index 9f74e259e3f6c32fc1f68c5cf8b247a15419e30e..318bb28f196e7afc3df3989fa3c5fe3328dd0499 100644 (file)
@@ -401,8 +401,17 @@ void QSGWindowsRenderLoop::renderWindow(QQuickWindow *window)
     if (!d->isRenderable())
         return;
 
-    if (!m_gl->makeCurrent(window))
-        return;
+    if (!m_gl->makeCurrent(window)) {
+        // Check for context loss.
+        if (!m_gl->isValid()) {
+            d->cleanupNodesOnShutdown();
+            m_rc->invalidate();
+            if (m_gl->create() && m_gl->makeCurrent(window))
+                m_rc->initialize(m_gl);
+            else
+                return;
+        }
+    }
 
     d->flushDelayedTouchEvent();
     // Event delivery or processing has caused the window to stop rendering.