A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Invalid BitmapData error - WHY?!?!

  1. #1
    Developer
    Join Date
    Apr 2007
    Location
    UK
    Posts
    324

    Invalid BitmapData error - WHY?!?!

    Sorry for multiple postage but I need this issue clearing up.

    To recreate my issue, create a document class with this code:

    Code:
    package {
        //
        import flash.display.Sprite
        import flash.display.BitmapData;
        //
        public class main extends Sprite {
            //
            var allData:Array = new Array();
            //
            public function main() {
                var n:int;
                for (n=0;n<9000;n++) {
                    var colour:int = Math.round(Math.random()*0xFFFFFF);
                    var myBD:BitmapData = new BitmapData(2, 2, false, colour);
                    allData[n] = myBD;
                }
            }
        }
    }
    This works fine and creates 9000 BitmapData objects.

    However, if you change the loop size to 10000(BEWARE - THIS MAY CRASH FLASH ENTIRELY), you will get an Invalid BitmapData error and sometimes (for me anyway) Flash will continually display dialog boxes the content of which I cannot actually see (might be a Vista thing) or just irrevocably crash.

    Note:all of the code is important - if you comment out the line which assigns the data to the array everything seems to work fine. I've never been more confused...

    Anyone got any ideas?

  2. #2
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    weird, Seems adding it to an array is whats causing the crash. The other reason may be the memory side, using more than your system has, but a 2x2 bitmap is probably not going to do that.

    sorry can't be more helpful, i'll try looking at different ways to add into the array
    lather yourself up with soap - soap arcade

  3. #3
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    creating so many bitmapdatas is crazy and its no wonder that it doesn´t work.
    If you have to create that many bitmapdatas then something is wrong with your setup.

  4. #4
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    to reply in a more productive manner:
    -no matter what you want to achieve, in an ordinary game setup you should never need more than a two digit amount of bitmapdata objects.
    Remember bitmapData is uncompressed image data and therefore a massive ram hugger, the less instances you need to get rolling the better.
    (Doesn´t mean you shouldn´t use em, it means you should try to get away with as few as possible).
    I´m not sure if trying to use that many bitmapdata objects just doesn´t work because of ram issues or because flash tries to prevent ram issues, in either case, yeah, its no good idea at all to have that many bitmdapata objects going.
    I´m not sure what you want to do, but let´s say for example you want to do a particle effect. You could have one stage bitmapdata, one buffer bitmapdata and one spritesheet bitmdapata, there you are, 3 bitmapdatas and you can display tons of particles just using copyPixels from one to the other.
    Sure the more graphically totally different objects you need the more spritesheets you may need etc, but as i said, try to keep the amount as low as possible, reuse old ones etc.

  5. #5
    Developer
    Join Date
    Apr 2007
    Location
    UK
    Posts
    324
    I unnderstand completely what you're getting at tomsamson but I specifically want to create multiple bitmap data objects. Also, as the objects are only 2by2, memory usage is trivial (about 14MB with 9000 objects in my specific test).

    Regardless of how rubbish it sounds, I want to be able to create as many BD objects as I want and add them to an array! Stupid buggy Flash...

  6. #6
    Senior Member rachil0's Avatar
    Join Date
    Jul 2007
    Location
    Columbus, OH.
    Posts
    465
    Wow, really strange. Can't really say I know why it's happening, just confirming that I can reproduce the problem. (Although it takes more bmpDatas for me to cause a crash). Some sort of overrun error is the most plausible explanation I can come up with. Perhaps there's some sort of handle mechanism that keeps track of bitmapDatas and it's possible to exhaust all the players bmpData handles? No clue

    I tend to agree that 10000 is a lot of bmpDatas for a sane application.

  7. #7
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    my guess for why it doesn´t work goes in a similar direction as rachil´s but yeah, again, i don´t get why one would seriously need that many bitmapdata objects. I´m pretty sure what you want to do probably can be achieved with 2-5 instances.

  8. #8
    Developer
    Join Date
    Apr 2007
    Location
    UK
    Posts
    324
    I might be able to simply change the way the instances are added to the array maybe...but still, I wish Flash would at least give me a reason for the crash...

    Oh and Im simply experimenting - I'm not creating a serious app.

  9. #9
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    To me it looks like this:
    first the reason why it crashes is not because of the way you add it to the array; its because you add it to the array at all.
    Let´s see: If you don´t add it to the array what happens? you have created a local variable inside a function with no active binding, you actually even create a new one each iteration with the same var name.
    So essentially when you create something as var in a function and it has no strong active bindings/references it should get kicked i guess.

    So what you do when you push it into the array is create an active strong reference, therefore the object will not get deleted automatically when the iteration is done.

    Anyway, doesn´t matter really, i´m all for experimentation, but yeah, you´re heading into the wrong direction there mate when you try to go for as many bitmapdatas as possible. You should go for achieving the same result (in functionality noticable to the viewer) with as few instances as possible.

  10. #10
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,377
    Not sure if it really matters, but have you tried declaring the array as simply [], or give it the length beforehand allData = new Array(9000); ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center