Android Surface deleted when game loose focus

S

Siracher

Guest
Hi

I create a new surface in my game and it works fine. Unfortunately I get an error once the game looses focus (for example when a call comes in or if a promo video is played). The surface will be deleted then for some reason and I get an error that the surface does not exist.

does anybody know what the best solution is to avoid that the surface will be deleted?
I don't think it makes sence to check all the time if the surface still exists and recreat it..?
 
L

Lonewolff

Guest
Code:
if(!surface_exists(some_surface))
       some_surface = surface_create(width, height);
 

TheSnidr

Heavy metal viking dentist
GMC Elder
Surfaces can be deleted at any time, and you do have to check whether or not it still exists whenever you use it.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
https://docs2.yoyogames.com/index.h...g/4_gml_reference/drawing/surfaces/index.html

First, you should realise that surfaces (except the application surface) are "volatile". This means that if the device or window loses focus or is minimised (good examples are when a screensaver comes up in Windows, or on an Android device when the app loses focus due to a call) then the surface may be destroyed. This is because it is stored in the texture memory and may be overwritten when the target platform needs that memory for something else which means that you should always have some type of fail-safe code in place, usually with the surface_exists function.
You would save yourself (and everyone else) some time if you'd check the manual before actually doing anything... ;)
 
S

Siracher

Guest
hi all thanks for the replies

I am aware of the surface exist function and read the manual.
But I just mentioned that I missed the essential part for my case, the draw event...
I thought it is too much to check each step if the surface still exists, but if it's the way it should be done, that's ok.

The example code below shows a typical use of this command in the draw event of an instance to check for a surface and re-create it if it has been removed.
thanks
 
M

maratae

Guest
hi all thanks for the replies

I am aware of the surface exist function and read the manual.
But I just mentioned that I missed the essential part for my case, the draw event...
I thought it is too much to check each step if the surface still exists, but if it's the way it should be done, that's ok.



thanks
From the manual:
First, you should realise that surfaces (except the application surface) are "volatile". This means that if the device or window loses focus or is minimised (good examples are when a screensaver comes up in Windows, or on an Android device when the app loses focus due to a call) then the surface may be destroyed.
So what @Nocturne said makes very sense, you see..
 
Top