From eeee9f1466ffaf17f81d635c2e43dca76ce5b021 Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Fri, 3 Jul 2015 10:55:35 +0200 Subject: QSGSimpleTextureNode: Fix ownership of QSGTexture Make sure the QSGSimpleTextureNode deletes the old QSGTexture if a new one is set via setTexture() and the ownsTexture flag is true. [ChangeLog][QtQuick][SceneGraph] QSGSimpleTextureNode will now delete the currently set QSGTexture object, if a new QSGTexture is set and the ownsTexture flag is on. Change-Id: Iabfbccd390e16948d4575baf29e6c8b4a184a404 Reviewed-by: Gunnar Sletta --- tests/auto/quick/nodes/tst_nodestest.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'tests/auto/quick/nodes') diff --git a/tests/auto/quick/nodes/tst_nodestest.cpp b/tests/auto/quick/nodes/tst_nodestest.cpp index b49ce34951..c49f01d5a7 100644 --- a/tests/auto/quick/nodes/tst_nodestest.cpp +++ b/tests/auto/quick/nodes/tst_nodestest.cpp @@ -283,7 +283,7 @@ void NodesTest::textureNodeTextureOwnership() QVERIFY(!texture.isNull()); } - { // Check that it is deleted when we so desire + { // Check that it is deleted on destruction when we so desire QPointer texture(new QSGPlainTexture()); QSGSimpleTextureNode *tn = new QSGSimpleTextureNode(); @@ -294,6 +294,25 @@ void NodesTest::textureNodeTextureOwnership() delete tn; QVERIFY(texture.isNull()); } + + { // Check that it is deleted on update when we so desire + QPointer oldTexture(new QSGPlainTexture()); + QPointer newTexture(new QSGPlainTexture()); + + QSGSimpleTextureNode *tn = new QSGSimpleTextureNode(); + tn->setOwnsTexture(true); + QVERIFY(tn->ownsTexture()); + + tn->setTexture(oldTexture); + QVERIFY(!oldTexture.isNull()); + QVERIFY(!newTexture.isNull()); + + tn->setTexture(newTexture); + QVERIFY(oldTexture.isNull()); + QVERIFY(!newTexture.isNull()); + + delete tn; + } } void NodesTest::textureNodeRect() -- cgit v1.2.3