• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

A question about surfaces, and sprite_create functions

In the manual when it talks about surfaces it's always pointed out that they are volatile, and as such unreliable. However, when talking about created sprites, such as sprite_create_from_surface, the same point is not made.

The manual says about having to clear up created sprites to avoid memory leaks, but doesn't mention in either of the create functions about volatility. Wouldn't both be volatile, as newly created data? Is this just an oversight in the explanation, or is there a difference somehow between a surface and a sprite created from that surface?

And one last question about this - on windows do you really need to pay much attention to surfaces disappearing, or is it largely on phones etc where there could be an issue?
 
I know that on a computer that if your application surface changes the size that your surface is destroyed, so yeah, they can disappear on windows (computers in general)
But is that something that would happen randomly, or would you as the programmer have to have done something that causes it?

Sorry - by windows, I meant computers in general. I'm curious to know why it might happen, but releasing on phones / tablets etc isn't of interest to me, so only pc and consoles is of concern.
 

Hyomoto

Member
Well, there is a difference. Sprite creation adds a new texture page, which are not volatile as far as I know, whereas surfaces can be flushed, such as when the application loses focus.

I don't know the technical differences between texture pages and surfaces, but that's why it isn't mentioned in sprite creation. You are making a new texture page from that surface, and thus it becomes a different type of data.

As for when surfaces are cleared... It's platform and situation dependent so there's no comprehensive list or anything. One thing I can say is they don't seem to disappear mid-frame, if you create it in the step event it should be there for the draw event. I haven't had any issues that way, but that's just my experience.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Sorry - by windows, I meant computers in general. I'm curious to know why it might happen, but releasing on phones / tablets etc isn't of interest to me, so only pc and consoles is of concern.
Minimising/maximising the game window, changing the window size, going full-screen, switching on v-sync... these are all things that can cause a surface to disappear. If anything, it's more likely on a PC since there are more things that can happen to cause it! On a mobile device, it'll only really happen when the app is pushed to the background or the screen is switched off. As for why they are volatile wwhen sprites are not, what @Hyomoto says is pretty much. They are stored in different ways...
 
@Hyomoto @Nocturne
Thanks ! That is what I wanted to know, as the sprite creation aspect was most significant. When you make a sprite of a surface it creates a new texture page - is there any way in game to order the texture page like you can do outside of the game? Or must they all remain one image per each new page?
 

Hyomoto

Member
@the_dude_abides - This has been discussed before, a search might find the relevant result, but the outcome was that it's simply not possible to combine assets into a single texture page at run time. I know some of that is this isn't expected to be the normal way of placing assets in game, and there is a workaround if you are willing to put the effort into it (though, admittedly still quite difficult and with tons of potential problems). You could take all the imported sprites, draw them to a surface, and then you could simply cut out the sprites you needed from that surface. I used a similar method to get around the GM2 beta limitation on sprites, though I'm certainly in no rush to try it again.
 
@Hyomoto
I think I get what you mean. By having them all on one surface, and turning it into a sprite, it can be used like a giant spritesheet that is just one texture page. But since its being made at runtime presumably you have to manually set up using it - things like the physical location of each separate "sprite" , and, as a rough guess if you're using it to have animated images, do your own animation system for it? If that's even anywhere near being close to what you have to do, then it does sound like a bit of a nightmare.

If there's a thread on this then I will try to find it. Thanks for the info!

EDIT: Found a thread that refers to a free marketplace asset that seems to be similar to what you're saying, so it's cool if you don't want to go into the details. Hopefully this covers it. Cheers!
 
Last edited:
Top