Fix texture leaks in QQuickCanvasItem
authorCharles Yin <charles.yin@nokia.com>
Wed, 7 Mar 2012 00:20:06 +0000 (10:20 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 7 Mar 2012 00:40:57 +0000 (01:40 +0100)
In commit be4c74948371ddf6f1ed260783b43b5a3d9e60a7 we removed the
QQuickCanvasItemNode, but textures are not automatically deleted with
QSGSimpleTextureNode, so add a very thin sub class of QSGSimpleTextureNode
to just cleanup canvas texture to avoid texture leaks.

Change-Id: I31aac1068e8218a75129b52afbbf30fb66e4bbf7
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
src/quick/items/context2d/qquickcanvasitem.cpp

index 3b4adc1..e2f57fe 100644 (file)
@@ -564,9 +564,16 @@ QSGNode *QQuickCanvasItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData
     if (!d->contextInitialized)
         return 0;
 
-    QSGSimpleTextureNode *node = static_cast<QSGSimpleTextureNode*>(oldNode);
+    class CanvasTextureNode : public QSGSimpleTextureNode
+    {
+    public:
+        CanvasTextureNode() : QSGSimpleTextureNode() {}
+        ~CanvasTextureNode() {delete texture();}
+    };
+
+    CanvasTextureNode *node = static_cast<CanvasTextureNode*>(oldNode);
     if (!node) {
-        node = new QSGSimpleTextureNode;
+        node = new CanvasTextureNode;
     }
 
     if (d->renderStrategy == QQuickCanvasItem::Cooperative)