Flash error - Invalid BitmapData

Discussion in 'Game Development (Technical)' started by Shaz, Mar 10, 2011.

  1. Shaz

    Moderator Original Member

    Joined:
    Feb 9, 2006
    Messages:
    405
    Likes Received:
    0
    Every now and then, my program throws error #2015 - Invalid BitmapData. Sometimes it's close to the start of the game, but mostly it's way in - after 15-20 minutes of playing.

    The line of code is
    var bd:BitmapData = new BitmapData(1024, 768, true, 0x00000000);

    This runs many times successfully, then suddenly throws an error. Running Windows 7 with Flash Player 10 (flashdevelop ide and Zinc). When this happens, I have over 2GB of free RAM.

    Does Flash, or Windows, allocate a RAM limit, and maybe I'm bumping into that?
     
  2. inverse

    Original Member

    Joined:
    Mar 3, 2005
    Messages:
    42
    Likes Received:
    0
    I don't know much about flash, but under 32-bit Windows, you will have a 2GB limit per process:

    http://msdn.microsoft.com/en-us/library/aa366778%28v=vs.85%29.aspx

    I doubt that's allocation/locking video memory in any way, but I suppose it might not be allocating from main RAM.

    I'd suggest keeping a running total of the size allocated up until the crash, then just do a simple loop allocating that much right at the start (i.e. try to break it intentionally).
     
  3. Shaz

    Moderator Original Member

    Joined:
    Feb 9, 2006
    Messages:
    405
    Likes Received:
    0
    thank you. Will give it a go :)
     
  4. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    Do you call dispose() when you don't need the data anymore? BitmapData's pixel data are not garbage collected.
     
  5. Shaz

    Moderator Original Member

    Joined:
    Feb 9, 2006
    Messages:
    405
    Likes Received:
    0
    Yes I do, on that class. I do have a few other classes that use bitmapdata, and I need to check those to ensure they clean up properly.
     
  6. HL706

    HL706 New Member

    Joined:
    Jan 20, 2011
    Messages:
    50
    Likes Received:
    0
    Are you certain it's the allocation of the BitmapData that's causing the problem? How are you using the data, is it possible your disposing it and then trying to access it shortly after?
     
  7. andrew

    andrew New Member

    Joined:
    Jan 14, 2007
    Messages:
    487
    Likes Received:
    0
    If you're running that "many times" you're creating 3-4 MB per call... print the running value of flash.system.System.totalMemory and make sure the garbage collector is working the way you think it is...

    - andrew
     
  8. Shaz

    Moderator Original Member

    Joined:
    Feb 9, 2006
    Messages:
    405
    Likes Received:
    0
    I can see that memory used creeps up a bit as I go to new scenes and doesn't decrease as much as I expect when I leave the scene SOMETIMES. So there are some things that aren't deallocating properly which I need to find.

    HL706, yes, it's the allocation of memory for the bitmapdata that's the problem. The game falls over on the BitmapData constructor. The crash is while the scene is loading, and I don't dispose of it until I leave the scene. I'm not trying to access something that's been disposed.

    Andrew, a lot of the calls are for smaller bitmaps, but that example is the maximum size I use, and the particular one that caused it to crash this time.

    Thanks for your suggestions - I should have come here a week ago!
     
  9. inverse

    Original Member

    Joined:
    Mar 3, 2005
    Messages:
    42
    Likes Received:
    0
    It's probably important to note, the memory allocation that causes the crash isn't necessarily the real problem (i.e. it's the "straw that broke the camel's back") - if something else is leaking, you're just more likely to run into the problem on a large allocation.
     
  10. Shaz

    Moderator Original Member

    Joined:
    Feb 9, 2006
    Messages:
    405
    Likes Received:
    0
    Yes, you're right.

    I did find some other bitmaps in a related class that weren't being disposed, and now I can get quite a lot further in the game without crashes. Of course there could still be other, smaller issues, but I still need to review all code looking for other things that aren't tidied up properly.

    Thanks everyone for your help :)
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer