user4441304
user4441304

Reputation:

GameMaker Studio - Non-Existing Surface

I am currently in the process of ironing out my engine created in GameMaker Studio. Currently, I am adding shadows and smooth effects to my engine.

As I was adding in these shadows, I have run into a problem, and have been able to narrow the problem down to a single line of code:

window_set_size(width, height);

I have set my width to 1024, and my height to 600. This is not the problem however. The problem, is when I run/debug my game, I am somehow invoking an error stated below:

ERROR in
action number 1
of  Step Event2
for object oGame:

Trying to use non-existing surface.
at gml_Script_lsys_update (line 58) -
   draw_surface_ext(global._lsys_light_surface[i], global._lsys_light_xpos[i] - global._lsys_light_radius[i], global._lsys_light_ypos[i] - global._lsys_light_radius[i], 1, 1, 0, global._lsys_light_color[i], 1);  
----------------------------------------------------------------------------    
stack frame is
gml_Script_lsys_update (line 58)
called from - gml_Object_oGame_StepEndEvent_1 (line 1) - lsys_update(alpha);

What I very loosely believe this to mean, is that drawing on my windows surface, somehow comes into conflict with setting the resolution of the acutal window itself. I have also included the scripts and commands you are reading in the error log below:

lsys_update

draw_surface_ext(global._lsys_light_surface[i], global._lsys_light_xpos[i] - global._lsys_light_radius[i], global._lsys_light_ypos[i] - global._lsys_light_radius[i], 1, 1, 0, global._lsys_light_color[i], 1);

Global Variables

global._lsys_lights = 0;
global._lsys_casters = 0;
global._lsys_quality = max(10/max(room_width, room_height), argument0);
global._lsys_surface = surface_create(room_width * global._lsys_quality, room_height * global._lsys_quality);

oGame End-Step Event

lsys_update(alpha); // Alpha is set to an Integer value of 0.5
surface_reset_target();

How am I meant to eliminate this error and fix my game?

Any help will be much appreciated. Please leave a comment if you require more information.

Upvotes: 1

Views: 1191

Answers (1)

Martin Bonde
Martin Bonde

Reputation: 556

Remember to check that the surface still exists before using it, using surface_exists, and create it again if it has disappeared from memory.

From the documentation:

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.

Upvotes: 2

Related Questions