I have a very complex Flash application (think Photoshop in Flash).
There is a lot of image manipulation, and all is working well with the exception of one bug.
The application has an undo/redo feature that sometimes throws an error. There is way too much code to paste here, but the issue revolves around this line of code:
trace("UNDO BMD: " + BeautyGlobal.undoArray[_undoSteps].bitmapData);
var newUndoData:BitmapData = BeautyGlobal.undoArray[_undoSteps].bitmapData.clone()
The trace statement displays:
UNDO BMD: [object BitmapData]
ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData/clone()
at Main/undoAction()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.beautyCanvas.ui::Toolbar/undoClick()
So there is bitmapdata there, but it is not valid. This issue doesn’t preset itself all of the time. If I could detect if the bitmap data is valid, I can stop it from crashing the entire application. I have tried a few things:
- check the height of the BM Data (crashes the app with same error)
- looping through the BMD to get all of the properties… nothing comes up even before the error presents itself.
Any suggestions would be greatly appreciated.
Thanks!
This is most likely because your application is using too much memory and has hit a limit. Check Flash Player’s memory usage.
A way to catch and deal with this error is to simply use a
try..catchblock:If you keep running into this error and can confirm that there is indeed a correlation with increased memory usage, then the one thing you want to do first is make sure that you are properly disposing of any discarded
BitmapDataobjects:Before you lose all references to a BitmapData instance, you want to
dispose()it first.