Keep m_states and m_sprites synchronized
authorAlan Alpert <alan.alpert@nokia.com>
Tue, 1 May 2012 05:17:16 +0000 (15:17 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 11 May 2012 02:47:41 +0000 (04:47 +0200)
Previously you could have more states than sprites, which could lead to
errors because the sprite engine assumes bounds checking was done by the
state engine (which only knows the size of the states list).

Change-Id: Ie6069caa96d01cc28cc79350e6db5ff4191831a8
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/quick/items/qquickspriteengine.cpp

index e6aec06..60d6edd 100644 (file)
@@ -341,13 +341,20 @@ void QQuickSpriteEngine::startAssemblingImage()
         return;
 
     //This could also trigger the start of the image loading in Sprites, however that currently happens in Sprite::setSource
+
+    QList<QQuickStochasticState*> removals;
+
     foreach (QQuickStochasticState* s, m_states){
         QQuickSprite* sprite = qobject_cast<QQuickSprite*>(s);
-        if (sprite)
+        if (sprite) {
             m_sprites << sprite;
-        else
+        } else {
+            removals << s;
             qDebug() << "Error: Non-sprite in QQuickSpriteEngine";
+        }
     }
+    foreach (QQuickStochasticState* s, removals)
+        m_states.removeAll(s);
     m_startedImageAssembly = true;
 }