From 97e553d578f251375a3f3affc8d5bbc5068d24a1 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Wed, 11 May 2011 07:55:56 +0200 Subject: [PATCH] Stop the render thread before deleting the QSGCanvas. --- src/declarative/items/qsgcanvas.cpp | 27 ++++++++++++++++++--------- src/declarative/items/qsgcanvas_p.h | 2 ++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/declarative/items/qsgcanvas.cpp b/src/declarative/items/qsgcanvas.cpp index 7b79748..15d301a 100644 --- a/src/declarative/items/qsgcanvas.cpp +++ b/src/declarative/items/qsgcanvas.cpp @@ -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); diff --git a/src/declarative/items/qsgcanvas_p.h b/src/declarative/items/qsgcanvas_p.h index c0aabaa..98c3d93 100644 --- a/src/declarative/items/qsgcanvas_p.h +++ b/src/declarative/items/qsgcanvas_p.h @@ -115,6 +115,8 @@ public: void sendHoverEvent(QEvent::Type, QSGItem *, QGraphicsSceneHoverEvent *); void clearHover(); + void stopRenderingThread(); + QDeclarativeGuard hoverItem; enum FocusOption { DontChangeFocusProperty = 0x01, -- 1.7.2.5