aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Koenig <tobias.koenig@kdab.com>2015-07-03 10:55:35 +0200
committerTobias Koenig <tobias.koenig@kdab.com>2015-07-03 17:10:15 +0000
commiteeee9f1466ffaf17f81d635c2e43dca76ce5b021 (patch)
treecb96f082237e9adb4290b428fcc36a8c6f9554a3
parent8b205fd05dcdc4a0e7ec6b25429f691a0a9099fe (diff)
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 <gunnar@sletta.org>
-rw-r--r--src/quick/scenegraph/util/qsgsimpletexturenode.cpp4
-rw-r--r--tests/auto/quick/nodes/tst_nodestest.cpp21
2 files changed, 23 insertions, 2 deletions
diff --git a/src/quick/scenegraph/util/qsgsimpletexturenode.cpp b/src/quick/scenegraph/util/qsgsimpletexturenode.cpp
index 8d38e83029..d9f3c44374 100644
--- a/src/quick/scenegraph/util/qsgsimpletexturenode.cpp
+++ b/src/quick/scenegraph/util/qsgsimpletexturenode.cpp
@@ -223,9 +223,11 @@ QRectF QSGSimpleTextureNode::sourceRect() const
void QSGSimpleTextureNode::setTexture(QSGTexture *texture)
{
Q_ASSERT(texture);
+ Q_D(QSGSimpleTextureNode);
+ if (d->ownsTexture)
+ delete m_material.texture();
m_material.setTexture(texture);
m_opaque_material.setTexture(texture);
- Q_D(QSGSimpleTextureNode);
qsgsimpletexturenode_update(&m_geometry, texture, m_rect, d->sourceRect, d->texCoordMode);
DirtyState dirty = DirtyMaterial;
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<QSGTexture> 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<QSGTexture> oldTexture(new QSGPlainTexture());
+ QPointer<QSGTexture> 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()