A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: AS3 - FD - Out of Memory problem.

  1. #1
    Junior Member
    Join Date
    Sep 2017
    Posts
    14

    AS3 - FD - Out of Memory problem.

    I'm doing a bit of code using FlashDevelop, and it's taking a png spritesheet which is embeded, then to get each frame, it takes the bitmake, using copyPixels to cut out the frame from the sheet, and puts it into an array.. all works fine, but I'm getting a memory problem..

    using the FD profiler (which i'll admit, I can't quite figure it out completely), claims it's only using 66,628kb.. where the windows task manager, it seams it's using about 600mb.. pretty high really but even that isn't as much as I would expect to crash..

    I'm kinda wondering if there is some way to compress the bitmap data (as in the variable type) or maybe some way of it being able to handle more then 600mb of memory... or any other sugguestions?

  2. #2
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,087
    dispose();

    Frees memory that is used to store the BitmapData object.

    maybe post screenshots or a record of what your trying to achieve.
    1ghz for an os for a game, ok maybe slow but 1ghz for a game with no os oof.

  3. #3
    Junior Member
    Join Date
    Sep 2017
    Posts
    14
    yeah, Dispose is a good thing to use, but.. i'll try to explain this better.. and show the part of the function that is the main problem to see if that helps..

    the spritesheets are embeded as classes, as per normal with such things. It is then put as a bitmap into an array with other sheets for access. When the sprites need to be loaded for the current scene, it takes the bitmapdata for the sheet(s) required, and using the size of each sprite (a standard size used for various ones) it uses the copypixels function of bitmapdata, to put each frame into a current active array. for animating the sprite, it just changes which element of the array it displays.

    disposing of the bitmapdata would, as I understand it, remove the data from the array which doesn't need to be done until later when its no longer needed.

    I would have thought that too much is being loaded into the array (which is vector.<bitmapdata>) but I have been able to load that amount into an array before, and the problem seams to be a sum total.. when I add X amount into one array, and then the same amount or atleast a set amount into a different array, this claims out of memory, despite the total memory usage being higher before, and reduced as things load and unload etc.

    the loading function.. if it makes sense with just this section (i'll be happy to explain bits if needed) is the following:

    Code:
    spriteArray = new Vector.<BitmapData>();
    			var i:int; // how many frames are in there
    			var h:int;
    			var r:Rectangle;
    			var p:Point;
    			var bd:BitmapData = new BitmapData(SpriteWidth, SpriteHeight);
    			TempArray= new Vector.<BitmapData>();
    			trace("AnimNum = " + AnimNum);
    			for (var SS:int = 0; SS < GraphicsFile.GPH[SheetName][AnimNum].Sheets.length; SS++)
    			{
    				//spriteSheet = (GraphicsFile.GPH[SheetName][AnimNum].Sheets[SS]).bitmapData; // store the bitmapdata taken from passed Array
    				i = Math.floor((GraphicsFile.GPH[SheetName][AnimNum].Sheets[SS]).bitmapData.width / SpriteWidth); // how many frames are in there
    				h = Math.floor((GraphicsFile.GPH[SheetName][AnimNum].Sheets[SS]).bitmapData.height / SpriteHeight);
    				r = new Rectangle(0,0,SpriteWidth,SpriteHeight);
    				p = new Point(); // why making N identical points? Just make one
    				//Not using SpriteSheet but replacing with direct comment to the bitmapData.. 
    				//does that save memory? or was SpriteSheet just working as a pointer..
    				trace("SS = " + SS);
    				trace("Array Count = " + spriteArray.length);
    				for (var k:int = 0; k < h; k++){
    					r.y = SpriteHeight * k; //Set up which row
    					for (var j:int = 0; j < i; j++) {
    						trace("K = " + k + ", J = " + j);
    						r.x = SpriteWidth * j; // update rectangle to cut next frame
    						bd.copyPixels((GraphicsFile.GPH[SheetName][AnimNum].Sheets[SS]).bitmapData, r, p); // cut the frame in a new BitmapData
    						if (ColourCheck(bd)){
    							spriteArray.push(bd); // store the frame
    						} else {
    							j = i;
    							k = h;
    						}
    					}
    				}
    			}
    the only thing I can really think is.. do I need to use copypixels like that.. or is it somehow possible to just kinda work like a pointer and point to the area of the bitmap data needed.. but I didn't think that was possible..

  4. #4
    Junior Member
    Join Date
    Sep 2017
    Posts
    14
    Had to go back to using the variable 'spriteSheet' to hold the data for the time being instead or directly referencing the embeded class bit cause it wasn't displaying any thing for the graphic so it didn't really make any difference. code not really change other then that..

    Kinda thinking I might need to do something like NOT embeding the files, but calling them from external... I do have some code for that I used for 'movies' so.. not too hard to add a bit.. could try it and see what happens..

  5. #5
    Junior Member
    Join Date
    Sep 2017
    Posts
    14
    after screwing around a bit and not quite seeing how anything has changed.. I seam to get a new error instead which.. has some interesting things to say..
    basically, 2015: Invalid Bitmapdata, called on the Bitmapdata/ctor .. this , as my understand goes, happens for one of two reasons:
    1) the Width and/or height for the new bitmpdata is 0. This is not the case and I can confirm that.
    2) too many bitmapdata files..

    now.. the second is.. probably a bit of a bugger to deal with.. for one thing.. I use the 'bd' variable as a storeAll for the cut up parts of the bitmaps. It's defined outside of the loop, inside the loop it sets it to a new Bitmapdata, then uses copyPixels to copy over the frame of animation from the spritesheet, then uses push to put the bd into an array.. then it loops around.. I was wondering if MAYBE, that was causing a bit of a memory leak and that I should dispose bd after pushing it into the array and before the next loop. However, when I do that, I do NOT get any of the data there.. as if the bd is pushed as a pointer more then the real data, and I get back to out of memory.. despite a low memory usage at this point..

    the quest continues

  6. #6

  7. #7
    Junior Member
    Join Date
    Sep 2017
    Posts
    14
    okay.. this has been a bit odd.. I've tried to do some optimising which seams to reduce the memory footprint, by NOT taking the embeded images, and then storing them in another variable as 'new <variable> as bitmap' BUT only doing that declaring bit when the image itself is called for loading. minor loading time increase, reduce memory footprint. it seam ^_^

    however, this doesn't seam to fix my problem.. Now the weird thing.. the ADL (AIR Debug Launcher) states it's version 24.0.0.180. I'm not sure if there is a newer version, but that one should be fine.. But I decided to run the swf via a exe frontend I've got setup for it (I wish to say, after taking a while to find out, Tim Goss, of Northcode, who's great SWF Studio was what I used to great the SWF, died after a long time recovering from a tragic car crash which killed his parents. I've had a number of e-mail converstations with him as well as on the old northcode message board and he was a great man and a sad loss and it's a big shame that Swf Studio is now dying.. due to a windows update, bits stopped working and he was working on an update but appears to have died before it was finished.. anyway, sorry for this distraction but I was kinda hit when I found out the reason I hadn't heard much from him in a while was due to his death, and cause I don't use facebook, I'm unable to send my consolations to his widow).. anyway.

    Using the exe version, which has a different player, it appears to.. work fine. so.. I'm not quite sure what's up there.. SO it means the project might be fine in the end BUT.. I can't debug at all.. i'm gonna have to look into that bit.. see if there is an upgrade, or maybe have to use a older version for testing.. I don't know.

  8. #8
    Junior Member
    Join Date
    Sep 2017
    Posts
    14
    Okay.. I tried updating the SDK in FlashDevelop.. ended up reporting tons of bugs with embed fonts which were fine before, and wouldn't compile, then trying to fix it I got the old java heap space errors, reinstalled and downloaded an older SDK and got that working.. but.. erm.. also not longer moaning about out of space and works fine.. so.. yeah. It appears to be all fine now..

Tags for this Thread

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