summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Nichols <andy.nichols@qt.io>2017-11-14 14:23:56 +0100
committerAndy Nichols <andy.nichols@qt.io>2017-11-15 10:13:52 +0000
commit9b6f95d64374338d00bc619acf30584c4ec78c4e (patch)
tree4c82e5a99defb4a10a21aac818e81bc2dcbdc768
parente20de2c1fd9d2c022e85c45885585ddc52bd0219 (diff)
downloadqt3d-9b6f95d64374338d00bc619acf30584c4ec78c4e.tar.gz
Fix AnimationClip crash when removing clips
Similar to ClipAnimators, it is important to take care when using these handles by checking if the frontend components have been destroyed already. Change-Id: I0dc3be94a6f0a7d5b064b864eed6cb2961b36ad9 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/animation/backend/handler.cpp11
-rw-r--r--src/animation/backend/handler_p.h1
-rw-r--r--src/animation/backend/loadanimationclipjob.cpp1
3 files changed, 13 insertions, 0 deletions
diff --git a/src/animation/backend/handler.cpp b/src/animation/backend/handler.cpp
index daa98ed54..c37db23cf 100644
--- a/src/animation/backend/handler.cpp
+++ b/src/animation/backend/handler.cpp
@@ -147,6 +147,16 @@ void Handler::setBlendedClipAnimatorRunning(const HBlendedClipAnimator &handle,
// The vectors may get outdated when the application removes/deletes an
// animator component in the meantime. Recognize this. This should be
// relatively infrequent so in most cases the vectors will not change at all.
+void Handler::cleanupHandleList(QVector<HAnimationClip> *clips)
+{
+ for (auto it = clips->begin(); it != clips->end(); ) {
+ if (!m_animationClipLoaderManager->data(*it))
+ clips->erase(it);
+ else
+ ++it;
+ }
+}
+
void Handler::cleanupHandleList(QVector<HClipAnimator> *animators)
{
for (auto it = animators->begin(); it != animators->end(); ) {
@@ -182,6 +192,7 @@ QVector<Qt3DCore::QAspectJobPtr> Handler::jobsToExecute(qint64 time)
// queue up a job for them
if (!m_dirtyAnimationClips.isEmpty()) {
qCDebug(HandlerLogic) << "Added LoadAnimationClipJob";
+ cleanupHandleList(&m_dirtyAnimationClips);
m_loadAnimationClipJob->addDirtyAnimationClips(m_dirtyAnimationClips);
jobs.push_back(m_loadAnimationClipJob);
m_dirtyAnimationClips.clear();
diff --git a/src/animation/backend/handler_p.h b/src/animation/backend/handler_p.h
index 467cd3a0e..11b06202b 100644
--- a/src/animation/backend/handler_p.h
+++ b/src/animation/backend/handler_p.h
@@ -117,6 +117,7 @@ public:
QVector<Qt3DCore::QAspectJobPtr> jobsToExecute(qint64 time);
+ void cleanupHandleList(QVector<HAnimationClip> *clips);
void cleanupHandleList(QVector<HClipAnimator> *animators);
void cleanupHandleList(QVector<HBlendedClipAnimator> *animators);
diff --git a/src/animation/backend/loadanimationclipjob.cpp b/src/animation/backend/loadanimationclipjob.cpp
index c0201e0e9..4584449bc 100644
--- a/src/animation/backend/loadanimationclipjob.cpp
+++ b/src/animation/backend/loadanimationclipjob.cpp
@@ -72,6 +72,7 @@ void LoadAnimationClipJob::run()
AnimationClipLoaderManager *animationClipManager = m_handler->animationClipLoaderManager();
for (const auto animationClipHandle : qAsConst(m_animationClipHandles)) {
AnimationClip *animationClip = animationClipManager->data(animationClipHandle);
+ Q_ASSERT(animationClip);
animationClip->loadAnimation();
}