--- a/modules/libpr0n/src/imgContainer.cpp
+++ b/modules/libpr0n/src/imgContainer.cpp
@@ -648,16 +648,24 @@ NS_IMETHODIMP imgContainer::GetDataSize(
imgFrame *frame = mFrames.SafeElementAt(i, nsnull);
NS_ABORT_IF_FALSE(frame, "Null frame in frame array!");
*_retval += frame->GetImageDataLength();
}
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)
{
NS_ABORT_IF_FALSE(framenum <= mFrames.Length(), "Invalid frame index!");
if (framenum > mFrames.Length())
return NS_ERROR_INVALID_ARG;
@@ -854,17 +862,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
@@ -200,16 +200,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();
PRUint32 GetCurrentImgFrameIndex() const;
inline Anim* ensureAnimExists()
{