2
votes

So, I'm porting a game, build for web flash in AIR Mobile (using FlashDevelop). Now, I have one class that runs first, which make vector graphic in bitmaps and re-size them as needed. Than, all this bitmaps (actually, BitmapData) are stored in Vectors. This class is a object of a Singelton class, which allows me easy access to the stored BimapData.

Also, I'm using FlashPunk as the game engine.

Now, I already created around 16 BitmapData and stored them in that class and everything is fine. But, the next BitmapData I add, in new Vector object, is not working as it should. Everything is fine while in RenderScreen, but as soon the game starts, e.g. click start game, it should return the BitmapData to create the menu, but it reports "ArgumentError: Error #2015: Invalid BitmapData"

What might be the problem? The BitmapData in question is created from vector graphic using draw(), scaled as needed, with initial width 1024px and height 120px. Also, the game run with around 40Mb memory, so the size is not the problem ...

Any idea why this error shows?

EDIT: I founded the problem and resolve it. How to close this question?

1
What's the original source of the BitmapData, and are you sure it's available at the time when you're calling for it?Amy Blankenship
Original source is Flash Sprite, vector graphic. And yes, it should be available, since the first thing the game does is to create these BitmapData objects.Than it store them as objects in a Singleton class. The problem occurs when I'm trying to create a Flashpunk object, like Stamp or Image. I call a function (UnitManager.getIstance().assets.getMenuItem(0);), which should return BitmapData, but it return invalid ...GeorgeCross
Is the Sprite on the stage or in the library? Note I'm deliberately not getting into how you're slitting your own throat by using Singleton ;)Amy Blankenship
The Sprite is in the library. Before the game starts, it creates all the sprites and movieclips, than it creates BitamapData objects and draw the sprites on them and than it stores them in Vectors. If I use the Bitmaps early, before the game starts, everything is alright, but after the game starts, I can use some of the Bitmaps but on one it throws the error. Singleton is not a good idea? I didn't know that ... Well, I'll try not to create all the bitmaps at start, but when the level is loaded. But, I have read that, usually, all of this Bitmaps are created before the game first start ...GeorgeCross
Alright, I founded the problem. In the RenderScreen, where I transform the vector graphic in BitmapDatas, I use a single bitmapData object to create the graphic, and as soon as they are created, a store them in a Vector<BitmapData>. And then, when all is finished, I used bitmapData.dispose(); and that is the problem. I'm destroying the bitmap data, but keeping the reference to that object in the Vector, so when I try to use it, it throws that error. I cannot believe that I wasted 10 hours on this ridiculous error. Well, that's life...GeorgeCross

1 Answers

1
votes

I'd bet my hat that it's a memory problem... error 2015 is either because one of the dimensions are invalid (width or height < 1 ), or because there is not enough memory to create the BitmapData.

The System class has a few properties that might help you debug the state of the memory before you try to create the conflicted BitmapData ;)

And if you find that it is actually a memory problem, besides wearing a new hat, you will have to rethink the way you cache those sprites... try to cache only the necessary pieces for each stage of the application, dispose them before you need to create more, etc. Good luck!