aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickspriteengine.cpp
diff options
context:
space:
mode:
authorJan Arve Saether <jan-arve.saether@digia.com>2014-10-03 10:56:48 +0200
committerJan Arve Sæther <jan-arve.saether@digia.com>2014-10-06 09:57:08 +0200
commit367fd6dd2860fe8c6a4f1a4f50b04de56450c76c (patch)
treeb9e2c097ca2deebb0ffb6bd8751c7216af06745e /src/quick/items/qquickspriteengine.cpp
parente076b8620367623b59309dd0a9cfdae18b13165a (diff)
Do not crash under certain conditions in AnimatedSprite
The code that tried to find the remaning number of frames on the last row was incorrect if the last row were full. It basically did totalNumberOfRows % framesPerRow, which doesn't always work, for instance: If the animation had 8 frames per row and a total of 16 frames the calculation to find the remaining number of frames became: 16 % 8 = 0 (correct result should have been 8) As you can see, it only didn't work in the cases where the last row were full. Change-Id: I9ff6ac7baa91538b01576b659ea6651992cfca0b Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'src/quick/items/qquickspriteengine.cpp')
-rw-r--r--src/quick/items/qquickspriteengine.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/quick/items/qquickspriteengine.cpp b/src/quick/items/qquickspriteengine.cpp
index 645830c014..097d512a43 100644
--- a/src/quick/items/qquickspriteengine.cpp
+++ b/src/quick/items/qquickspriteengine.cpp
@@ -201,10 +201,12 @@ int QQuickSpriteEngine::spriteFrames(int sprite)
extra = (m_sprites[state]->m_generatedCount - 1) - extra;
- if (extra == m_sprites[state]->m_generatedCount - 1)//last state
- return m_sprites[state]->frames() % m_sprites[state]->m_framesPerRow;
- else
- return m_sprites[state]->m_framesPerRow;
+ if (extra == m_sprites[state]->m_generatedCount - 1) {//last state
+ const int framesRemaining = m_sprites[state]->frames() % m_sprites[state]->m_framesPerRow;
+ if (framesRemaining > 0)
+ return framesRemaining;
+ }
+ return m_sprites[state]->m_framesPerRow;
}
int QQuickSpriteEngine::spriteDuration(int sprite)//Full duration, not per frame
@@ -219,10 +221,12 @@ int QQuickSpriteEngine::spriteDuration(int sprite)//Full duration, not per frame
if (m_sprites[state]->reverse())
extra = (m_sprites[state]->m_generatedCount - 1) - extra;
- if (extra == m_sprites[state]->m_generatedCount - 1)//last state
- return m_duration[sprite] % rowDuration;
- else
- return rowDuration;
+ if (extra == m_sprites[state]->m_generatedCount - 1) {//last state
+ const int durationRemaining = m_duration[sprite] % rowDuration;
+ if (durationRemaining > 0)
+ return durationRemaining;
+ }
+ return rowDuration;
}
int QQuickSpriteEngine::spriteY(int sprite)