Bug 547143. r=jrmuizel sr=roc
authorJoe Drew <joe@drew.ca>
Mon, 08 Mar 2010 14:01:04 -0500
changeset 33713 dcf4c045d75348784616bf4f85e67103bb9c0379
parent 33712 9dc0e565cba1c46e30b7b9c388bf32501f9474d7
child 33714 39676a222968e3b0e40a3ba4a97fdf2c11ec5bfa
push id1142
push usertimeless@mozdev.org
push dateTue, 09 Mar 2010 14:35:12 +0000
reviewersjrmuizel, roc
bugs547143
milestone1.9.2.2pre
Bug 547143. r=jrmuizel sr=roc a=beltzner
modules/libpr0n/src/imgContainer.cpp
modules/libpr0n/src/imgContainer.h
--- a/modules/libpr0n/src/imgContainer.cpp
+++ b/modules/libpr0n/src/imgContainer.cpp
@@ -393,16 +393,24 @@ NS_IMETHODIMP imgContainer::GetFrameColo
   if (!frame->GetIsPaletted())
     return NS_ERROR_FAILURE;
 
   frame->GetPaletteData(aPaletteData, aPaletteLength);
 
   return NS_OK;
 }
 
+void imgContainer::DeleteImgFrame(PRUint32 framenum)
+{
+  NS_ABORT_IF_FALSE(framenum < mFrames.Length(), "Deleting invalid frame!");
+
+  delete mFrames[framenum];
+  mFrames[framenum] = nsnull;
+}
+
 nsresult imgContainer::InternalAddFrameHelper(PRUint32 framenum, imgFrame *aFrame,
                                               PRUint8 **imageData, PRUint32 *imageLength,
                                               PRUint32 **paletteData, PRUint32 *paletteLength)
 {
   if (framenum > PRUint32(mNumFrames))
     return NS_ERROR_INVALID_ARG;
 
   nsAutoPtr<imgFrame> frame(aFrame);
@@ -535,17 +543,17 @@ NS_IMETHODIMP imgContainer::EnsureCleanF
                             /* aPaletteDepth = */ 0, imageData, imageLength,
                             /* aPaletteData = */ nsnull, 
                             /* aPaletteLength = */ nsnull);
 
   // See if we can re-use the frame that already exists.
   nsIntRect rect = frame->GetRect();
   if (rect.x != aX || rect.y != aY || rect.width != aWidth || rect.height != aHeight ||
       frame->GetFormat() != aFormat) {
-    delete frame;
+    DeleteImgFrame(aFrameNum);
     return InternalAddFrame(aFrameNum, aX, aY, aWidth, aHeight, aFormat, 
                             /* aPaletteDepth = */ 0, imageData, imageLength,
                             /* aPaletteData = */ nsnull, 
                             /* aPaletteLength = */ nsnull);
   }
 
   // We can re-use the frame.
   frame->GetImageData(imageData, imageLength);
--- a/modules/libpr0n/src/imgContainer.h
+++ b/modules/libpr0n/src/imgContainer.h
@@ -190,16 +190,26 @@ private:
     }
     ~Anim()
     {
       if (timer)
         timer->Cancel();
     }
   };
 
+  /**
+   * Deletes and nulls out the frame in mFrames[framenum].
+   *
+   * Does not change the size of mFrames.
+   *
+   * @param framenum The index of the frame to be deleted. 
+   *                 Must lie in [0, mFrames.Length() )
+   */
+  void DeleteImgFrame(PRUint32 framenum);
+
   imgFrame* GetImgFrame(PRUint32 framenum);
   imgFrame* GetDrawableImgFrame(PRUint32 framenum);
   imgFrame* GetCurrentImgFrame();
   imgFrame* GetCurrentDrawableImgFrame();
   PRInt32 GetCurrentImgFrameIndex() const;
   
   inline Anim* ensureAnimExists() {
     if (!mAnim)