diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-02-16 11:32:33 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-03-03 18:05:14 +0000 |
commit | 0e30dc40df70cef2cd3f31b913bf867a620327cb (patch) | |
tree | 971afe01ee262838247feb4ca776016327e6587d /tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp | |
parent | 0e0c351fff752ceadc99eef5fbcf5a180f453efc (diff) |
AnimatedSprite: don't access deleted scene graph nodes
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 <gunnar@sletta.org>
Diffstat (limited to 'tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp')
-rw-r--r-- | tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
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 <QtQuick/qquickview.h> #include <private/qabstractanimation_p.h> #include <private/qquickanimatedsprite_p.h> +#include <private/qquickitem_p.h> #include <QtGui/qpainter.h> #include <QtGui/qopenglcontext.h> #include <QtGui/qopenglfunctions.h> @@ -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<QQuickAnimatedSprite*>("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) |