src/hbcore/image/hbiconanimation.cpp
changeset 28 b7da29130b0e
parent 21 4633027730f5
--- a/src/hbcore/image/hbiconanimation.cpp	Thu Sep 02 20:44:51 2010 +0300
+++ b/src/hbcore/image/hbiconanimation.cpp	Fri Sep 17 08:32:10 2010 +0300
@@ -335,7 +335,8 @@
     mImageRenderer(renderer),
     mIconFileName(iconFileName),
     mType(type),
-    mTimerEntry(0)
+    mTimerEntry(0),
+    mDoNotResetLoopCount(false)
 {
     // This class supports these types
     Q_ASSERT(mType == MNG || mType == GIF);
@@ -400,11 +401,15 @@
         mImageRenderer = 0;
         mImageRenderer = new QImageReader(mIconFileName, mType == MNG ? "MNG" : "GIF");
 
-        // Reset the loop count.
-        if (mCustomLoopCountSet) {
-            mLoopCount = mCustomLoopCount;
+        if (mDoNotResetLoopCount) {
+            mDoNotResetLoopCount = false;
         } else {
-            mLoopCount = mImageRenderer->loopCount();
+            // Reset the loop count.
+            if (mCustomLoopCountSet) {
+                mLoopCount = mCustomLoopCount;
+            } else {
+                mLoopCount = mImageRenderer->loopCount();
+            }
         }
 
         // New image reader starts from the first frame. Handle animation update.
@@ -433,6 +438,9 @@
             QImage img = mImageRenderer->read();
             // Reached last frame?
             if (!mImageRenderer->canRead()) {
+                // Must get rid of the old pixmap first, in case of very large frames
+                // keeping both the old and new frame in memory would not succeed.
+                mCurrentFrame = QPixmap(); // This call is not superfluous.
                 mCurrentFrame = QPixmap::fromImage(img);
                 mLastFrame = mCurrentFrame;
                 break;
@@ -528,6 +536,11 @@
 
     // Store the new frame in the current frame pixmap
     if (!img.isNull()) {
+        // Must get rid of the old pixmap first, in case of very large frames
+        // keeping both the old and new frame in memory would not succeed.
+        // (with the OpenVG paint engine QPixmap will create a new QImage if
+        // the pixel format is different and it will be different here...)
+        mCurrentFrame = QPixmap(); // This call is not superfluous.
         mCurrentFrame = QPixmap::fromImage(img);
     }
     // Reached the last frame. Store it so it can be used by stop().
@@ -551,6 +564,7 @@
             if (mLoopCount > 0) {
                 --mLoopCount;
             }
+            mDoNotResetLoopCount = true;
             start();
         }
     }