Posted: 6th Dec 2011 23:30
I have encountered a problem as I've built up my game. I can run my menu system perfectly, moving around the different menus and options. Each one starts from nothing and loads the button image, creates sprites and text, then deletes them all after an option is taken. If the option is another menu, it starts all over again. I can do this all day long with no issues.

Once I play the game, the menu graphics lose their transparency, bit by bit (as you can see below it's not all), and ultimately deleted sprites leave white blocks behind. The "Play Game" option is currently just loading three images and sprites, moving them around a bit, then deleting them again.

Any ideas?

Posted: 7th Dec 2011 4:53
For me, it seems a problem of graphics memory, or related to its use. Have you done a test on another PC? Its an idea.
Posted: 7th Dec 2011 6:51
I'm not sure about this one BatVink. If you like post the project (or code in question) and I'd be happy to go through it.

For me, it seems a problem of graphics memory,

I've seen that problem too except in this case he seems to be able to load them and draw them and then they disappear. If it were a graphical memory problem I don't think he'd see them at all.
Posted: 7th Dec 2011 8:55
Not had this issue. Is there any reason you can't load the images just once? Maybe it's related to reloading the same image over and again after physics or something else has been initialised?
Posted: 7th Dec 2011 10:24
Don't know about your problem. I don't think you are running out of memory on a PC.

But you should not be loading a ton of button images. It would be best to load a single button background and then create text objects from a custom text image. Should be much faster and take up less memory.
Posted: 7th Dec 2011 10:32
But you should not be loading a ton of button images. It would be best to load a single button background and then create text objects from a custom text image. Should be much faster and take up less memory.

I got the impression that's how it's being done already.

Are you using a background image or setting the refresh colour? Maybe it's the screen not fully refreshing? Add a screen sized sprite the same colour as your background behind the menu sprites maybe?

EDIT: One final thought, are you deleting / hiding the sprites or are you just setting the image to zero? A zero imageID would cause a white sprite too...
Posted: 7th Dec 2011 10:40
Have you done a test on another PC?


I get the problem on 2 PCs and an Android phone

But you should not be loading a ton of button images. It would be best to load a single button background and then create text objects from a custom text image. Should be much faster and take up less memory.


I load one image and create all buttons from it (Sprite + Text overlaid). When a selection is made, I unload the sprites, image and text. If a new menu is required, I load the image again and repeat.

Is there any reason you can't load the images just once? Maybe it's related to reloading the same image over and again after physics or something else has been initialised?

I will try loading it just once to see what impact this has. The reason for reloading is that this is a standalone piece of code, that I can drop into any project to create menus. Loading the image for each menu makes it more portable and configurable.
There's no physics involved, so this can discounted.

Are you using a background image or setting the refresh colour? Maybe it's the screen not fully refreshing? Add a screen sized sprite the same colour as your background behind the menu sprites maybe?

This may have started when I changed the refresh colour to a dark grey from the default black. I'll check that too

are you deleting / hiding the sprites or are you just setting the image to zero? A zero imageID would cause a white sprite too

I deleteSprite() followed by deleteImage(). But the effect is almost like I deleted the image and the sprite stayed.

I'll report back when I've tested again later, thanks for all the ideas
Posted: 7th Dec 2011 11:35
null, sorry.
Posted: 7th Dec 2011 16:48
How do you deleteSprite() and deleteImage()? (post code)

Try like this:
+ Code Snippet
If GetImageExists( ImageID ) = 1 Then DeleteImage( ImageID )
ImageID = 0
If GetSpriteExists( SpriteID ) = 1 Then DeleteSprite( SpriteID )
SpriteID = 0

Or like this:
+ Code Snippet
DeleteImage( GetSpriteImageID( SpriteID ) )
DeleteSprite( SpriteID )
SpriteID = 0


May not change anything, but give it a go and see if it helps.
Posted: 7th Dec 2011 20:36
I worked it out by not deleting the image at the end of the menu. I had a typo in my code and I wasn't deleting the sprites. So sprites with no image were showing as white.

AGK can be very forgiving, but it can result in the program continuing to run with bugs in it. This is the second time my program has refused to die - it will continue through a divide by zero too
Posted: 8th Dec 2011 1:12
I am afraid that was my 'bright idea'. The 'app that cannot be killed' is part of the promise that when your app finds itself in a strange land on an alien device, it doesn't turn green and die, it takes a deep breath and gives it a bloody good go, warts and all. We could add some sort of 'sensitive mode' when bombs out the moment something slightly naughty happens with an appropriate error, maybe set in the IDE so you can quickly switch it on/off.

My grand plan was to put this (and more) into the suspiciously absent debugger tool, which would not only stop at the offending line, but show you what it expected, what it got, what it looks like, where it came from, why it happened and a suggestion on what you can do to fix it.
Posted: 8th Dec 2011 8:22
It's a great bright idea - I think developers need an insight into what will get captured and how it is dealt with. We now know through trial and error a /0 returns 0, and you can deleteSprite() on an invalid id.

The debugging plan sounds good