diff options
author | Gunnar Sletta <gunnar.sletta@jollamobile.com> | 2014-05-15 21:01:06 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-19 11:15:08 +0200 |
commit | 851ae1a77dc207ec11b8ed3f0786bfe1c1905e4c (patch) | |
tree | 6576f581a94851366e4481ea6994b610636f5fe0 /src/quick/util/qquickanimatorcontroller.cpp | |
parent | 8f6254a88e4c634203df779aa385d9955e91b56f (diff) |
Fix crash with running animators on re-shown windows.
The non-threaded render loops would clean up the nodes for a window
when it was hidden, but the animators kept running and had a reference
to the deleted nodes. This was not a problem for the threaded render
loop as it would wipe the animator controller as well which would
clean the jobs.
Fix it by triggering a reset of all nodes in the animators when the
window is told to clean up. If an animator is ticked when it doesn't
have a node, it will simply do nothing. When the window is made visible
again, we call initialize on all animators to find the new node.
Task-number: QTBUG-37995
Change-Id: Ie5609d95db29f4b2b30ca5bf641dce901e528389
Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'src/quick/util/qquickanimatorcontroller.cpp')
-rw-r--r-- | src/quick/util/qquickanimatorcontroller.cpp | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/src/quick/util/qquickanimatorcontroller.cpp b/src/quick/util/qquickanimatorcontroller.cpp index 7991dd8110..697c25b211 100644 --- a/src/quick/util/qquickanimatorcontroller.cpp +++ b/src/quick/util/qquickanimatorcontroller.cpp @@ -54,6 +54,7 @@ QT_BEGIN_NAMESPACE QQuickAnimatorController::QQuickAnimatorController() : m_window(0) + , m_nodesAreInvalid(false) { } @@ -80,6 +81,26 @@ QQuickAnimatorController::~QQuickAnimatorController() } } +static void qquickanimator_invalidate_node(QAbstractAnimationJob *job) +{ + if (job->isRenderThreadJob()) { + static_cast<QQuickAnimatorJob *>(job)->nodeWasDestroyed(); + } else if (job->isGroup()) { + QAnimationGroupJob *g = static_cast<QAnimationGroupJob *>(job); + for (QAbstractAnimationJob *a = g->firstChild(); a; a = a->nextSibling()) + qquickanimator_invalidate_node(a); + } +} + +void QQuickAnimatorController::windowNodesDestroyed() +{ + m_nodesAreInvalid = true; + for (QHash<QAbstractAnimationJob *, QQuickAnimatorProxyJob *>::const_iterator it = m_animatorRoots.constBegin(); + it != m_animatorRoots.constEnd(); ++it) { + qquickanimator_invalidate_node(it.key()); + } +} + void QQuickAnimatorController::itemDestroyed(QObject *o) { m_deletedSinceLastFrame << (QQuickItem *) o; @@ -112,7 +133,7 @@ void QQuickAnimatorController::advance() m_window->update(); } -static void qquick_initialize_helper(QAbstractAnimationJob *job, QQuickAnimatorController *c) +static void qquick_initialize_helper(QAbstractAnimationJob *job, QQuickAnimatorController *c, bool attachListener) { if (job->isRenderThreadJob()) { QQuickAnimatorJob *j = static_cast<QQuickAnimatorJob *>(job); @@ -121,13 +142,14 @@ static void qquick_initialize_helper(QAbstractAnimationJob *job, QQuickAnimatorC } else if (c->m_deletedSinceLastFrame.contains(j->target())) { j->targetWasDeleted(); } else { - j->addAnimationChangeListener(c, QAbstractAnimationJob::StateChange); + if (attachListener) + j->addAnimationChangeListener(c, QAbstractAnimationJob::StateChange); j->initialize(c); } } else if (job->isGroup()) { QAnimationGroupJob *g = static_cast<QAnimationGroupJob *>(job); for (QAbstractAnimationJob *a = g->firstChild(); a; a = a->nextSibling()) - qquick_initialize_helper(a, c); + qquick_initialize_helper(a, c, attachListener); } } @@ -147,7 +169,7 @@ void QQuickAnimatorController::beforeNodeSync() foreach (QQuickAnimatorProxyJob *proxy, m_starting) { QAbstractAnimationJob *job = proxy->job(); job->addAnimationChangeListener(this, QAbstractAnimationJob::Completion); - qquick_initialize_helper(job, this); + qquick_initialize_helper(job, this, true); m_animatorRoots[job] = proxy; job->start(); proxy->startedByController(); @@ -160,6 +182,18 @@ void QQuickAnimatorController::beforeNodeSync() } m_stopping.clear(); + // First sync after a window was hidden or otherwise invalidated. + // call initialize again to pick up new nodes.. + if (m_nodesAreInvalid) { + for (QHash<QAbstractAnimationJob *, QQuickAnimatorProxyJob *>::const_iterator it = m_animatorRoots.constBegin(); + it != m_animatorRoots.constEnd(); ++it) { + qquick_initialize_helper(it.key(), this, false); + } + m_nodesAreInvalid = false; + } + + + foreach (QQuickAnimatorJob *job, m_activeLeafAnimations) { if (!job->target()) continue; |