From 815b4b463da83802f535b328d7ef699aea529a6b Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 13 Feb 2012 10:11:26 +1000 Subject: Don't crash when an animation update causes it to delete itself. Change-Id: Ic108adfb99a09e6ede71d474240fb0917cee6961 Reviewed-by: Bea Lam --- .../data/deleteOnUpdate.qml | 27 ++++++++++++++++++++++ .../tst_qdeclarativesmoothedanimation.cpp | 19 +++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/auto/qtquick2/qdeclarativesmoothedanimation/data/deleteOnUpdate.qml (limited to 'tests') diff --git a/tests/auto/qtquick2/qdeclarativesmoothedanimation/data/deleteOnUpdate.qml b/tests/auto/qtquick2/qdeclarativesmoothedanimation/data/deleteOnUpdate.qml new file mode 100644 index 0000000000..ff8dfaa846 --- /dev/null +++ b/tests/auto/qtquick2/qdeclarativesmoothedanimation/data/deleteOnUpdate.qml @@ -0,0 +1,27 @@ +import QtQuick 2.0 + +Rectangle { + width: 300; height: 300; + + Rectangle { + color: "red" + width: 60; height: 60; + x: 100; y: 100; + + property real prevX: 100 + onXChanged: { + if (x - prevX > 10) { + anim.to += 5 + anim.restart(); //this can cause deletion of backend animation classes + prevX = x; + } + } + + SmoothedAnimation on x { + id: anim + objectName: "anim" + velocity: 100 + to: 150 + } + } +} diff --git a/tests/auto/qtquick2/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp b/tests/auto/qtquick2/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp index 3d37517d10..09bde4ad76 100644 --- a/tests/auto/qtquick2/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp +++ b/tests/auto/qtquick2/qdeclarativesmoothedanimation/tst_qdeclarativesmoothedanimation.cpp @@ -59,6 +59,7 @@ private slots: void simpleAnimation(); void valueSource(); void behavior(); + void deleteOnUpdate(); private: QDeclarativeEngine engine; @@ -218,6 +219,24 @@ void tst_qdeclarativesmoothedanimation::behavior() delete rect; } +void tst_qdeclarativesmoothedanimation::deleteOnUpdate() +{ + QDeclarativeEngine engine; + + QDeclarativeComponent c(&engine, testFileUrl("deleteOnUpdate.qml")); + + QQuickRectangle *rect = qobject_cast(c.create()); + QVERIFY(rect); + + QDeclarativeSmoothedAnimation *anim = rect->findChild("anim"); + QVERIFY(anim); + + //don't crash + QTest::qWait(500); + + delete rect; +} + QTEST_MAIN(tst_qdeclarativesmoothedanimation) #include "tst_qdeclarativesmoothedanimation.moc" -- cgit v1.2.3