Delete QQuickWindow's animator driver at the right time.
authorGunnar Sletta <gunnar@sletta.org>
Thu, 2 Jul 2015 13:54:43 +0000 (15:54 +0200)
committerLiang Qi <liang.qi@theqtcompany.com>
Sat, 4 Jul 2015 19:59:52 +0000 (19:59 +0000)
For the non-threaded renderloops, we there might be a timer firing
before the animationController is cleaned up through deleteLater()
which will then reference the deleted QQuickWindow. Rely instead on
direct and explicit cleanup at the right time in each render loop.

Change-Id: Id81daddae78ce3922d6a932fb21200f2dc7955bb
Task-number: QTBUG-33723
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
src/quick/items/qquickwindow.cpp
src/quick/scenegraph/qsgrenderloop.cpp
src/quick/scenegraph/qsgthreadedrenderloop.cpp
src/quick/scenegraph/qsgwindowsrenderloop.cpp

index 84b585e3b5b6995f7db675580ab0c5e0fd3b5cdf..4238787cc8608e4fbaa84bf0c31d525c2fb99065 100644 (file)
@@ -1112,7 +1112,6 @@ QQuickWindow::~QQuickWindow()
 {
     Q_D(QQuickWindow);
 
-    d->animationController->deleteLater();
     if (d->renderControl) {
         QQuickRenderControlPrivate::get(d->renderControl)->windowDestroyed();
     } else if (d->windowManager) {
index ec9c3c39f95caf8315e551f598017acc5e13b2b5..4d3f34c71c7f8abc41d3c583ee81c6fb23733b13 100644 (file)
@@ -34,6 +34,7 @@
 #include "qsgrenderloop_p.h"
 #include "qsgthreadedrenderloop_p.h"
 #include "qsgwindowsrenderloop_p.h"
+#include <private/qquickanimatorcontroller_p.h>
 
 #include <QtCore/QCoreApplication>
 #include <QtCore/QTime>
@@ -305,6 +306,8 @@ void QSGGuiThreadRenderLoop::windowDestroyed(QQuickWindow *window)
     } else if (gl && window == gl->surface() && current) {
         gl->doneCurrent();
     }
+
+    delete d->animationController;
 }
 
 void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
index 56637387df15752071ed2ce9bc98cc2c6a8e9063..2cebbaf4843da04fadb1b2e9f2bd2cd15c13f2c1 100644 (file)
@@ -451,11 +451,12 @@ void QSGRenderThread::invalidateOpenGL(QQuickWindow *window, bool inDestructor,
         qCDebug(QSG_LOG_RENDERLOOP) << QSG_RT_PAD << "- cleanup without an OpenGL context";
     }
 
+    QQuickWindowPrivate *dd = QQuickWindowPrivate::get(window);
+
     QQuickShaderEffectMaterial::cleanupMaterialCache();
 
     // The canvas nodes must be cleaned up regardless if we are in the destructor..
     if (wipeSG) {
-        QQuickWindowPrivate *dd = QQuickWindowPrivate::get(window);
         dd->cleanupNodesOnShutdown();
     } else {
         qCDebug(QSG_LOG_RENDERLOOP) << QSG_RT_PAD << "- persistent SG, avoiding cleanup";
@@ -467,6 +468,8 @@ void QSGRenderThread::invalidateOpenGL(QQuickWindow *window, bool inDestructor,
     sgrc->invalidate();
     QCoreApplication::processEvents();
     QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+    if (inDestructor)
+        delete dd->animationController;
     if (current)
         gl->doneCurrent();
     qCDebug(QSG_LOG_RENDERLOOP) << QSG_RT_PAD << "- invalidating scene graph";
index c571e600189c008d637a5a70ba8ca6ef5327ed2c..7fd965161825014d01cd0352ff9e7c9a81c30c0a 100644 (file)
@@ -32,7 +32,6 @@
 ****************************************************************************/
 
 #include "qsgwindowsrenderloop_p.h"
-
 #include <QtCore/QCoreApplication>
 #include <QtCore/QLibraryInfo>
 #include <QtCore/QThread>
@@ -47,8 +46,8 @@
 #include <QtQuick/QQuickWindow>
 
 #include <private/qquickprofiler_p.h>
-
 #include <private/qquickshadereffectnode_p.h>
+#include <private/qquickanimatorcontroller_p.h>
 
 QT_BEGIN_NAMESPACE
 
@@ -219,6 +218,7 @@ void QSGWindowsRenderLoop::windowDestroyed(QQuickWindow *window)
     hide(window);
 
     QQuickWindowPrivate *d = QQuickWindowPrivate::get(window);
+
     bool current = false;
     QScopedPointer<QOffscreenSurface> offscreenSurface;
     if (m_gl) {
@@ -245,6 +245,8 @@ void QSGWindowsRenderLoop::windowDestroyed(QQuickWindow *window)
     } else if (m_gl && current) {
         m_gl->doneCurrent();
     }
+
+    delete d->animationController;
 }
 
 bool QSGWindowsRenderLoop::anyoneShowing() const