From f9f99c43fbea600f61d065b30a5453e95dfa6ade Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Mon, 7 Dec 2015 09:04:00 +0100 Subject: QQuickAnimatorJob: store the target with a QPointer This avoids ending up with invalid pointers when under some circumstances the target (which is not owned by the QQuickAnimatorJob) is destroyed between the time the QQuickAnimatorJob is created and the time it is initialized. This is the case when the target of an Animator is the item loaded by a Loader and that the animator is started just before setting the Loader to inactive. Also added an auto test for that special case. Task-number: QTBUG-49634 Change-Id: Iab9bfe76d13755ba735432c6f97bde175d308814 Reviewed-by: Thomas McGuire Reviewed-by: Gunnar Sletta --- src/quick/util/qquickanimatorcontroller.cpp | 5 +++++ src/quick/util/qquickanimatorjob_p.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/quick/util/qquickanimatorcontroller.cpp b/src/quick/util/qquickanimatorcontroller.cpp index cfb6037d14..74930fb373 100644 --- a/src/quick/util/qquickanimatorcontroller.cpp +++ b/src/quick/util/qquickanimatorcontroller.cpp @@ -140,6 +140,11 @@ static void qquick_initialize_helper(QAbstractAnimationJob *job, QQuickAnimatorC { if (job->isRenderThreadJob()) { QQuickAnimatorJob *j = static_cast(job); + // Note: since a QQuickAnimatorJob::m_target is a QPointer, + // if m_target is destroyed between the time it was set + // as the target of the animator job and before this step, + // (e.g a Loader being set inactive just after starting the animator) + // we are sure it will be NULL and won't be dangling around if (!j->target()) { return; } else if (c->m_deletedSinceLastFrame.contains(j->target())) { diff --git a/src/quick/util/qquickanimatorjob_p.h b/src/quick/util/qquickanimatorjob_p.h index 82c9da1d2e..35057d6278 100644 --- a/src/quick/util/qquickanimatorjob_p.h +++ b/src/quick/util/qquickanimatorjob_p.h @@ -152,7 +152,7 @@ protected: QQuickAnimatorJob(); void debugAnimation(QDebug d) const Q_DECL_OVERRIDE; - QQuickItem *m_target; + QPointer m_target; QQuickAnimatorController *m_controller; qreal m_from; -- cgit v1.2.3