From 0e30dc40df70cef2cd3f31b913bf867a620327cb Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 16 Feb 2016 11:32:33 +0100 Subject: AnimatedSprite: don't access deleted scene graph nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s a bad idea to store a scene graph paint node as a member variable. First of all, it should not access the node outside updatePaintNode(), that is, outside the render thread. Secondly, the node is owned by the scene graph and may be nuked whenever the scene graph feels so. Some creative re-parenting easily triggers a case where AnimatedSprite ends up accessing a node that was already deleted by the scene graph. Change-Id: I89205ac36333a2fcb094121afa61b6409fda5883 Task-number: QTBUG-51162 Reviewed-by: Gunnar Sletta --- .../tst_qquickanimatedsprite.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp index c9e1a43414..3cb7ff511f 100644 --- a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp +++ b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,7 @@ private slots: void test_frameChangedSignal(); void test_largeAnimation_data(); void test_largeAnimation(); + void test_reparenting(); }; void tst_qquickanimatedsprite::initTestCase() @@ -268,6 +270,26 @@ void tst_qquickanimatedsprite::test_largeAnimation() delete window; } +void tst_qquickanimatedsprite::test_reparenting() +{ + QQuickView window; + window.setSource(testFileUrl("basic.qml")); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + QVERIFY(window.rootObject()); + QQuickAnimatedSprite* sprite = window.rootObject()->findChild("sprite"); + QVERIFY(sprite); + + QTRY_VERIFY(sprite->running()); + sprite->setParentItem(0); + + sprite->setParentItem(window.rootObject()); + // don't crash (QTBUG-51162) + sprite->polish(); + QTRY_COMPARE(QQuickItemPrivate::get(sprite)->polishScheduled, true); + QTRY_COMPARE(QQuickItemPrivate::get(sprite)->polishScheduled, false); +} QTEST_MAIN(tst_qquickanimatedsprite) -- cgit v1.2.3