Stop managing lifetime of material
authorAlan Alpert <alan.alpert@nokia.com>
Thu, 22 Sep 2011 04:06:05 +0000 (14:06 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 22 Sep 2011 06:23:18 +0000 (08:23 +0200)
Let scenegraph handle it in its own thread.

Task-number: QTBUG-21586
Change-Id: I5affcec4abbc79fff0c60e740d2c1cf04e3385f2
Reviewed-on: http://codereview.qt-project.org/5345
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>

src/declarative/particles/qsgimageparticle.cpp

index dd50ce2..872624e 100644 (file)
@@ -667,7 +667,6 @@ QSGImageParticle::QSGImageParticle(QSGItem* parent)
 
 QSGImageParticle::~QSGImageParticle()
 {
-    delete m_material;
 }
 
 QDeclarativeListProperty<QSGSprite> QSGImageParticle::sprites()
@@ -1106,10 +1105,8 @@ QSGGeometryNode* QSGImageParticle::buildParticleNodes()
     }
 
     clearShadows();
-    if (m_material) {
-        delete m_material;
+    if (m_material)
         m_material = 0;
-    }
 
     //Setup material
     QImage colortable;
@@ -1212,8 +1209,9 @@ QSGGeometryNode* QSGImageParticle::buildParticleNodes()
 
     foreach (QSGGeometryNode* node, m_nodes){
         if (node == *(m_nodes.begin()))
-            continue;
-        (*(m_nodes.begin()))->appendChildNode(node);
+            node->setFlag(QSGGeometryNode::OwnsMaterial);//Root node owns the material for memory management purposes
+        else
+            (*(m_nodes.begin()))->appendChildNode(node);
     }
 
     return *(m_nodes.begin());
@@ -1224,15 +1222,13 @@ QSGNode *QSGImageParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *)
     if (m_pleaseReset){
         m_lastLevel = perfLevel;
 
-        delete m_rootNode;//Automatically deletes children
+        delete m_rootNode;//Automatically deletes children, and SG manages material lifetime
         m_rootNode = 0;
         m_nodes.clear();
 
         m_idxStarts.clear();
         m_lastIdxStart = 0;
 
-        if (m_material)
-            delete m_material;
         m_material = 0;
 
         m_pleaseReset = false;