Don't dereference a null animationTemplate

If the SpringAnimation gets used inside a Transition, the
animationTemplate might get cleared, but updateCurrentTime()
still gets called on the SpringAnimation after that.

Task-number: QTBUG-34539
Change-Id: I1f27fdbfc594e6ff9a4343e45f7f4001964bb012
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
This commit is contained in:
Lars Knoll 2013-11-13 08:32:12 +01:00 committed by The Qt Project
parent 44e204ea9d
commit 23680b185d
3 changed files with 34 additions and 1 deletions

View File

@ -308,7 +308,8 @@ void QSpringAnimation::updateCurrentTime(int time)
QQmlPropertyPrivate::DontRemoveBinding);
if (stopped && old_to == to) { // do not stop if we got restarted
stopTime = animationTemplate->elapsed.elapsed();
if (animationTemplate)
stopTime = animationTemplate->elapsed.elapsed();
stop();
}
}

View File

@ -0,0 +1,22 @@
import QtQuick 2.0
Rectangle {
width: 250
height: 250
ListView {
anchors.fill: parent
model: ListModel {
ListElement { text: "A" }
ListElement { text: "B" }
}
populate: Transition {
SpringAnimation { properties: "x"; from: 0; to: 100; spring: 4; damping: 0.3 }
}
delegate: Text {
text: "Test"
}
}
}

View File

@ -41,6 +41,7 @@
#include <qtest.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>
#include <QtQuick/qquickview.h>
#include <private/qquickspringanimation_p.h>
#include <private/qqmlvaluetype_p.h>
#include "../../shared/util.h"
@ -55,6 +56,7 @@ private slots:
void defaultValues();
void values();
void disabled();
void inTransition();
private:
QQmlEngine engine;
@ -128,6 +130,14 @@ void tst_qquickspringanimation::disabled()
delete obj;
}
void tst_qquickspringanimation::inTransition()
{
QQuickView view(testFileUrl("inTransition.qml"));
view.show();
// this used to crash after ~1 sec, once the spring animation was done
QTest::qWait(2000);
}
QTEST_MAIN(tst_qquickspringanimation)
#include "tst_qquickspringanimation.moc"