actionscript 3 - AS3 new BitmapData(w,h); gets ArgumentError: Error #2015: Invalid, works for a while then stops with this error -


I have a game that produces a new part of the field, because the player has estimated that the unlimited level size Is allowed. It's working perfectly, but I decided to move my character for a long time in one direction, and eventually this error happened:

  Logic: Error # 2015: Invalid bitmap data. Flash.display :: bitmapData / ctor () at flash.display :: bitmapData ()   

On this line of code:

  this.new_chunk. Background_bitmap_data = new bitmapdata (this.level_obj.block_size * this.new_chunk.blocks_wide + this.level_obj.oversize_bmd_offset, this.level_obj.block_size * this.new_chunk.blocks_tall + this.level_obj.oversize_bmd_offset, true, 0x00000000);   

I have a trace on extreme and equations; , which provides the width and height value used to create bitmap data, and it outputs the same values ​​as the constant, such as:

  2150 1300   

I participated in many different directions in my character, and the same thing ultimately happens regardless of direction. I know that Bitmapadata is not being too big, because it is always 2150x1300

Note: An error does not occur while staying in a small area, no matter how long Until I leave the game, the error occurs only after traveling for a long time in one direction, causing many new fragmentation to occur

Edit:

This game Has a live demo so you can get a better understanding ofWhat's happening:

(Controls are WASD for speed, keep pressing shift to move faster.)

Each "share" is the size of the game screen , Each segment has a cached repository to make BitmapData of small codes (tiles of grass, trees, rocks, flowers etc.) Chuck code Code> bitmap , when this part is close to the stage, which is to eliminate it Can end the need.

Edit 2:

I uploaded a picture to clarify that I believe the proposed method of Amy required to be provided for my game That does not require the storage of several bitmapadata objects:

Enter image details here

Colored areas of the four corners Bitmapdata objects that have a bit on the screen Map will be drawn on (the same size as the user's screen, shown in green.) The black area around the whole thing indicates that one point could be the other BitMapData objects They are set to null because they are no longer required.

The 4-corner BitmapData objects will be recreated as a player moves with a new point coordinator from the main bitmap .

I was going straight in the north with shift for 5 minutes, the memory consumption increased to 3+ GIB and then I got out of RAM, so it started using swap and Too slow down.

So, I think that you get out of memory, and the error of flash is a little strange for that matter. Try to free the old bitmap, or even better to reuse it. Recommended approaches are usually screen-size 4 bitmaps, used to re-use west for new areas in the past, when you go east, for the poem and north and south.

Besides, I see a very annoying blinking white strip. I do not know exactly what the reason is, but usually occurs when no one uses double-buffering.

Comments