surface_set_target() bug

S

squirrelah

Guest
Hello, i have a game where i am constantly drawing a surface across the entire screen and using it as a "fog of war". Technically i am drawing two surfaces, one black one and one transparent one, and this is the transparent one but i don't think thats relevant.

Basically whenever i am debugging and i minimize, and then unminimize i get the error

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object oFog:

Trying to set a surface target that does not exist.
at gml_Object_oFog_Step_0 (line 2) - surface_set_target(sFog);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_oFog_Step_0 (line 2)



Below is my code for all 3 events.
Code:
////STEP CODE
surface_set_target(sFog);

draw_clear(c_gray);

surface_reset_target();


//////DRAW CODE

draw_surface_ext(sFog, 0, 0, res, res, 0, 0, .5);

///////CREATE CODE

res = 3;
depth = -7;
sFog = surface_create(room_width/res,room_height/res);
Does anyone know why this is happening or how to fix it?
 
Surfaces are removed when the screen is minimized. Check if a surface exists before doing anything with it. If it doesn't, recreate it.
 

12spoon

Member
Surfaces are "volatile" and can cease to exist if the window loses focus. Before targeting or drawing the surface, you can check if it exists using "surface_exists()" and recreate it if it doesn't.
 
S

squirrelah

Guest
I have another related question. Is there a way to save what was drawn or is that just outside the ability of surfaces to handle?

I have it so it doesn't error out anymore, but when i minimize and unminimize it clears the entire screen because the original black surface is only created once when the room loads. I am not really sure how to trigger it to redraw when the screen unminimizes and i think even if i did it wouldn't save the image.

I will also need to be able to save it for future saving/loading purposes but if that's not possible i might as well rebuild it all from the ground up(not that its that involved currently, i'd just prefer to not have to do that if i dont have to).
 
Top