Fix not having a context when cleaning up on Windows
authorLaszlo Agocs <laszlo.agocs@digia.com>
Thu, 6 Nov 2014 21:06:26 +0000 (13:06 -0800)
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Mon, 10 Nov 2014 08:48:51 +0000 (09:48 +0100)
The same old issue surfaces in the windows render loop too.
The basic render loop is already fixed, apply a similar patch
to the windows one too.

Task-number: QTBUG-42213
Change-Id: I07068315f5164014e329b8ce061947c97ae9da61
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
src/quick/scenegraph/qsgwindowsrenderloop.cpp

index 070d6b8..1213c7e 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <QtGui/QScreen>
 #include <QtGui/QGuiApplication>
+#include <QtGui/QOffscreenSurface>
 
 #include <QtQuick/private/qsgcontext_p.h>
 #include <QtQuick/private/qquickwindow_p.h>
@@ -210,15 +211,29 @@ void QSGWindowsRenderLoop::windowDestroyed(QQuickWindow *window)
     hide(window);
 
     QQuickWindowPrivate *d = QQuickWindowPrivate::get(window);
-    if (m_gl)
-        m_gl->makeCurrent(window);
+    bool current = false;
+    QScopedPointer<QOffscreenSurface> offscreenSurface;
+    if (m_gl) {
+        QSurface *surface = window;
+        // There may be no platform window if the window got closed.
+        if (!window->handle()) {
+            offscreenSurface.reset(new QOffscreenSurface);
+            offscreenSurface->setFormat(m_gl->format());
+            offscreenSurface->create();
+            surface = offscreenSurface.data();
+        }
+        current = m_gl->makeCurrent(surface);
+    }
+    if (Q_UNLIKELY(!current))
+        qCDebug(QSG_LOG_RENDERLOOP) << "cleanup without an OpenGL context";
+
     d->cleanupNodesOnShutdown();
     if (m_windows.size() == 0) {
         d->context->invalidate();
         QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
         delete m_gl;
         m_gl = 0;
-    } else if (m_gl) {
+    } else if (m_gl && current) {
         m_gl->doneCurrent();
     }
 }