Shoebox memory leak

Previous topic - Next topic

Crivens

I posted this elsewhere but thought here would be better.

This code on the iPhone keeps building up used memory until it eventually crashes:-
Code (glbasic) Select
ttime=GETTIMERALL()
ttotal=0
tsprite=GENSPRITE()
WHILE 1=1
IF GETTIMERALL()-ttime>100 
LOADSPRITE "Media/1-1.png",tsprite
INC ttotal
ttime=GETTIMERALL()
ENDIF
PRINT ttotal,0,0,10
SHOWSCREEN
WEND


If I use a loadsprite "",tsprite directly after the loadsprite command it makes no difference. From the graph in XCode you can see it gives back a little memory when loading the sprite again (seen by spikes in graph), but nowhere near enough.

Cheers

[attachment deleted by admin]
Current fave quote: Cause you like musicians and I like people with boobs.

Kitty Hello

Can you try to find out what functions allocate but don't release.

Try the code on windows and it will not leak, right?


Crivens

I believe it's the loadsprite command. You can load the same sprite file over the top of the same sprite bank (as example shows) and the allocated memory on an iDevice just keeps building. The graph shows a small amount is released every time but only a tiny amount. After my memory is used up (just after 256mb) then it crashes as can be seen in the screenshot.

My PC is fine in the task manager, but as someone else mentioned earlier this doesn't show memory used by the video card, whereas the iPhone has it all in one memory allocation.

I removed the printing on the screen incase fonts were causing the leak, and tried a loadsprite "",tsprite after every loadsprite to see if that cleared memory, to no effect.

The only other thing I just thought of is that the image I have loading comes from a shoebox on the iPhone. Doubt it makes a difference, but you never know.

If I get a chance tonight I will modify to just have a while/wend with a loadsprite command inside it and nothing else. So is the same idea with it loading the same image into the same bank, but with nothing else at all. I'll also try without a shoebox.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

MrTAToad

Yes, try it without shoebox as well, just in case.

Kitty Hello

Oh! Shoebox might ring a bell!!

Can you please try without? I tries with the MESA OpenGL wrapper on Windows and still no leak.

Kitty Hello

In that program, before you delete / overwrite the texture, please try: X_SETTEXTURE -1, -1, 0

It might be that GLBasic can't delete a texture if it's still bound. That would explain it.

Crivens

Ok, will try a few things tonight. Didn't get the chance yesterday.

Also on the question of sprites, is there a way to load them at a certain percentage size? I know you can resize when you draw them, but I was thinking of when everything is loaded at different resolutions to save memory and speed (rather than loading everything full size then resizing when drawing the sprite).

Essentially I was thinking of a routine that would take the resolution (specifically thinking of iOS here) and load all the sprites and save them back as the correct size for the resolution. So if you have an image of 500x500 and that's for the max res screen of 640x960 (iPhone 4), then getting a screen res of 640x960 would keep the image the same size, but a screen res of 320x480 (iPhone <4) would paste it to the screen but resized at 50% ratio, then grab it again as the sprite to use (or even save as the proper sprite). So would end up with a 250x250 sprite for future use.

The main problem I see with this idea is partially transparent sprites (is it alphablended sprites?). By making the backscreen pink then pasting a sprite should keep the transparency when I re-grab it. But does GLB support partially transparent sprites? If so then I'm stuck there. It would overall be much nicer if we could load a sprite at a set percentage. That way a pre iPhone 4 would load the sprite at 50% (in both X and Y) size, resulting in using up 25% of the memory it should take up, plus obviously it will be faster than the zoom sprite commands. Or to have a save sprite command that can save the sprite at a set percentage, keeping all transparency (including partial transparency) settings. That one would be quite good actually as we can then save new smaller sprites and the loading should be faster in the future as it wouldn't have to load a big sprite and then then resize it into memory. What do you think?

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

ampos

I had this solution on the iphone:

media/1024
media/960
media/480

in the program, you check the screen resolution and setmediadir ("media/"+resolution)

Also, notice you have to define "pixel size"

480=1px
960=2px
1024=2.13px

and every sprite movement is *PIXEL so they always move at the same speed in all resolutions.

But if you are thinking in porting your programs in the future for other devices (android can had tons of resolutions) I use this pixel size table:

Code (glbasic) Select
// MODO 1=320x240 (1x) 2=480x320 (IPhone 1.5x) 3=640x400 (2x) 4=960x640 (Iphone4 3x) 5=1024x768 (IPad 3.2x) 6=1280x1024 (4x)

GETSCREENSIZE xres,yres
IF yres>=320 AND xres>=240
modo=1;ratio=1
ENDIF
IF yres>=480 AND xres>=320
ratio=1.5;modo=2
ENDIF
IF yres>=640 AND xres>=400
ratio=2;modo=3
ENDIF
IF yres>=960 AND xres>=640
ratio=3;modo=4
ENDIF
IF yres>=1024 AND xres>=768
ratio=3.2;modo=5
ENDIF
IF yres>=1280 AND xres>=1024
modo=6;ratio=4
ENDIF
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Crivens

Yeah, I was going to do something similar, except use a calculated ratio on the final draw. So I would calculate all movements, for example, based on an iPhone 4 resolution, then when actually drawing the sprites to the screen I would then use the calculated ratio for the exact positioning. eg. we are working on a 640x960 grid, but my calculated ratio is 0.5 (probably best to do one for X and one for Y to be 100%) as the target resolution is 320x480. So I may store an objects location at 600x900, but because of the ratio then when it actually draws it to the screen it will be 300x450. Combined with a setup that recalculates all sprite file sizes to the correct resolution then should be stress free (ish). Just must remember to draw everything using the ratio. eg. drawsprite 10,x*r,y*r. Should work fine.

Still, would be nice to have one set of highest resoltion images then resize and reload based on targets resolution. Which is where my routine, or ideally a loadsprite/savesprite command with an optional percentage parameter would come in handy.

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

Crivens

Yes, this error is to do with Shoebox. I just tried a project from scratch and loaded in sprites from set media and it works just fine. This was with loading the same sprite file into the same sprite bank every 100 milliseconds. I didn't bother with using the clear sprite command. Memory is allocated and it goes up and down a bit but overall it stays at the same level. Delete the image and use a shoebox instead and the memory keeps getting used up.

Ah well, I was a bit off shoebox anyway because it doesn't work for Wav for me on iOS, plus I think I'm being a bit anal if I think it looks a bit amateur to see all you image files in an iPhone explorer. At the end of the day who does that really? Plus it's not as if I am doing amazing graphics or anything.

Any chance of that loadsprite/savesprite command that loads them in at a set percentage or pixel size (both for X and Y)?

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

erico

Quote from: Crivens on 2011-Mar-18
plus I think I'm being a bit anal if I think it looks a bit amateur to see all you image files in an iPhone explorer. At the end of the day who does that really?

Use to do it all the time on the amiga on games that was possible to do so.
I didn't quite bother if that was amateur, at the end of the day I was really happy to see the gfx sheets.
I consider that a FEATURE hehe

heck I even do it on MAME once in a while and I remember reassembling RENEGADES's grafics once...

Crivens

Yeah, me too. But on the iPhone it's that one level up where you need to download an explorer app to see the files on your iPhone. Literally that leaves people like us not your average Joe. I can live with that until I reach graphics perfection (which will be a long time away...)

Cheers
Current fave quote: Cause you like musicians and I like people with boobs.

MrTAToad

Ah, so it is shoebox, eh ?

doimus

Quote from: Crivens on 2011-Mar-18
Yeah, me too. But on the iPhone it's that one level up where you need to download an explorer app to see the files on your iPhone. Literally that leaves people like us not your average Joe.


You can consider your graphics as free marketing tool.
<--- See my avatar. It's from Monkey Island 2. I like it so much that I'm advertising it with each post.  :)
Somebody might use your graphics in their online profiles or whatever and essentially advertise your game.

Also, many games come with "Art of..." books and soundtrack CDs that are part of "limited editions". It's the most efficient counter-piracy method that has worked since forever.
If you have graphics that are somewhat worth looking at, consider actually publishing them separately, or even putting them on your website for free!

Crivens

For me it wasn't really about letting people use my graphics or not. It was more about looking a bit naff and amateur hour when using an iPhone explorer to view all the files. I don't really see that for other apps. On the other hand, as said earlier, it isn't the end of the world as you would have to be a bit geeky (like us) to even think of doing such a thing anyway, and as far as I know it's not as if iTunes shows it easily.

Cheers

Current fave quote: Cause you like musicians and I like people with boobs.