Rewrite QAnimationGroupJob::clear() method
authorCharles Yin <charles.yin@nokia.com>
Tue, 3 Apr 2012 06:52:29 +0000 (16:52 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 5 Apr 2012 06:33:59 +0000 (08:33 +0200)
Before removing and deleting children, set the m_group to 0 to avoid potential
cycling deletions when this method is called from QAnimationGroupJob::~QAnimationGroupJob().

Change-Id: Idb6920be71fc9e033e5a76b724c9550018995035
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
src/qml/animations/qanimationgroupjob.cpp

index 83b2192..59bceaa 100644 (file)
@@ -51,8 +51,7 @@ QAnimationGroupJob::QAnimationGroupJob()
 
 QAnimationGroupJob::~QAnimationGroupJob()
 {
-    while (firstChild() != 0)
-        delete firstChild();
+    clear();
 }
 
 void QAnimationGroupJob::topLevelAnimationLoopChanged()
@@ -123,9 +122,16 @@ void QAnimationGroupJob::removeAnimation(QAbstractAnimationJob *animation)
 
 void QAnimationGroupJob::clear()
 {
-    //### should this remove and delete, or just remove?
-    while (firstChild() != 0)
-        delete firstChild(); //removeAnimation(firstChild());
+    QAbstractAnimationJob *child = firstChild();
+    QAbstractAnimationJob *nextSibling = 0;
+    while (child != 0) {
+         child->m_group = 0;
+         nextSibling = child->nextSibling();
+         delete child;
+         child = nextSibling;
+    }
+    m_firstChild = 0;
+    m_lastChild = 0;
 }
 
 void QAnimationGroupJob::resetUncontrolledAnimationsFinishTime()