Stop the render thread before deleting the QSGCanvas.
authorGunnar Sletta <gunnar.sletta@nokia.com>
Wed, 11 May 2011 05:55:56 +0000 (07:55 +0200)
committerGunnar Sletta <gunnar.sletta@nokia.com>
Wed, 11 May 2011 11:16:01 +0000 (13:16 +0200)
src/declarative/items/qsgcanvas.cpp
src/declarative/items/qsgcanvas_p.h

index 7b79748..15d301a 100644 (file)
@@ -106,6 +106,19 @@ QSGRootItem::QSGRootItem()
 {
 }
 
+void QSGCanvasPrivate::stopRenderingThread()
+{
+    if (thread->isRunning()) {
+        mutex.lock();
+        exitThread = true;
+        wait.wakeOne();
+        wait.wait(&mutex);
+        exitThread = false;
+        mutex.unlock();
+        thread->wait();
+    }
+}
+
 void QSGCanvasPrivate::_q_animationStarted()
 {
 #ifdef THREAD_DEBUG
@@ -239,15 +252,8 @@ void QSGCanvas::hideEvent(QHideEvent *e)
 {
     Q_D(QSGCanvas);
 
-    if (d->threadedRendering) {
-        d->mutex.lock();
-        d->exitThread = true;
-        d->wait.wakeOne();
-        d->wait.wait(&d->mutex);
-        d->exitThread = false;
-        d->mutex.unlock();
-        d->thread->wait();
-    }
+    if (d->threadedRendering)
+        d->stopRenderingThread();
 
     d->animationDriver->uninstall();
 
@@ -916,6 +922,9 @@ QSGCanvas::~QSGCanvas()
 {
     Q_D(QSGCanvas);
 
+    if (d->threadedRendering)
+        d->stopRenderingThread();
+
     // ### should we change ~QSGItem to handle this better?
     // manually cleanup for the root item (item destructor only handles these when an item is parented)
     QSGItemPrivate *rootItemPrivate = QSGItemPrivate::get(d->rootItem);
index c0aabaa..98c3d93 100644 (file)
@@ -115,6 +115,8 @@ public:
     void sendHoverEvent(QEvent::Type, QSGItem *, QGraphicsSceneHoverEvent *);
     void clearHover();
 
+    void stopRenderingThread();
+
     QDeclarativeGuard<QSGItem> hoverItem;
     enum FocusOption {
         DontChangeFocusProperty = 0x01,