GameMaker Memory chewed up when window is resized.

C

Consuming Octorocks

Guest
I'm trying to make my game have display options which you can resize the window in a menu. When I use window_set_size to change the display via button, the game runs ok for a few seconds but then slows down really hard. I have no idea what the issue is with it and even made it so every time you change the display it restarts the game in case its a memory thing or something.

Also after the resize, the game chews up a lot of my memory so that might be it but im not sure
 
C

Consuming Octorocks

Guest
@andev I just tried it and nothing changes. The game starts off fine but the game slows down over the span of about a minuet my ram usage slowly shifts from about 3 gigs to 16 (all of my ram) and in then it crashes.

Before I made the game resizable, this didn't happen. I had the game be fullscreen at 1080p and everything was fine. I have no clue why resizing it creates a memory leak.
 

andev

Member
1. Try it in a blank project
2. Do a global search in your project for all size related code. window_get_width(), view_* etc. And don't stop there, look at what those things interact with and so on
3. Create a duplicate project, comment everything out, and start uncommenting until the issue appears.
 
C

Consuming Octorocks

Guest
@andev I did some troubleshooting and apparently it appears that if I disable my lighting, the problem fixes its self.
:/


Kinda wanted lighting tho.
 
C

Consuming Octorocks

Guest
@trentallain after you set the display size, i have the game restart. Wouldn't that automatically delete the surface? Also the surface is created with a few scripts which are executed by an object that controls the lighting. I used the lighting from this video
if that helps. Also if you couldn't tell, i'm not very experienced in GM2. I just started a few months ago.
 
T

trentallain

Guest
@trentallain after you set the display size, i have the game restart. Wouldn't that automatically delete the surface? Also the surface is created with a few scripts which are executed by an object that controls the lighting. I used the lighting from this video
if that helps. Also if you couldn't tell, i'm not very experienced in GM2. I just started a few months ago.
Unless you save the settings in a save file and read them on startup, wouldn't the resizing only happen after you restart?
 
T

trentallain

Guest
Are you putting the resizing stuff in a create event or something like a key check pressed so it doesn't run every step?
 
C

Consuming Octorocks

Guest
@trentallain I have buttons you press to change the size of the window. Once one of these is pushed, the game saves the new display size into a .ini file, and then the game restarts (completely). The new display size is loaded from the file and the window is resized in the "Game Start" event
 

Mike

nobody important
GMC Elder
Run it in the debugger and have a look at the surfaces, make sure they are all being disposed properly....sounds like you have a leak in the lighting system.
 
O

orSQUADstra

Guest
If it's up to surfaces, make sure to redraw the surface on reisizing and do a surface_free to free the surface from the memory, that's what I think might be causing the issue.
 
C

Consuming Octorocks

Guest
@SQUADstra So I Put a surface_free code somewhere in there and it works kinda. However, when i first start the game, it brings up several errors that i have to ignore. I think i should just post the code XD.
Object that controls the lighting :
Code:
light_layer = layer_get_id("Lighting");
light_surface = surface_create(1920,1080);
surface_width = global.DisplayWidth;
surface_height = global.DisplayHeight;

layer_script_begin(light_layer, lighting_start);
layer_script_end(light_layer, lighting_stop);
global.DisplayWidth and global.DisplayHeight is the new window size and those variables are loaded from a .ini file when the game starts (in case thats important)

lighting_start script :
Code:
if (event_type == ev_draw) and (event_number == 0) {
    if (!surface_exists(!obj_Light_Controller.light_surface)) {
        obj_Light_Controller.light_surface = surface_create(obj_Light_Controller.surface_width,obj_Light_Controller.surface_height);
    }
 
    var cam = view_camera[view_current];
 
    surface_set_target(obj_Light_Controller.light_surface);
 
    camera_apply(cam);
 
 
 
    surface_set_target(obj_Light_Controller.light_surface);
    draw_clear_alpha(obj_Light_Controller.darkness,1.0);
    gpu_set_blendmode(bm_add);
    surface_reset_target();
}
lighting_stop script :
Code:
if (event_type == ev_draw) and (event_number == 0)
{
    surface_reset_target();
    gpu_set_blendmode(bm_normal);

    surface_set_target(application_surface); 
        gpu_set_blendmode_ext(bm_dest_color,bm_zero); 
        draw_surface(obj_Light_Controller.light_surface,0,0);
        surface_free(obj_Light_Controller.light_surface);
        gpu_set_blendmode(bm_normal);
    surface_reset_target();
}
 
I would suggest two things:
1. Resize your window so it runs slowly, and profile to see what's going on: https://www.yoyogames.com/blog/44/profiling-your-games-performance
(in GMS2, while debugging, the profiler is located under the "Other" tab

2. Do not render the light surfaces unless they can actually be seen by the player.
Create a buffer around the player, the width and height of the screen.
Don't draw the light unless it's origin + radius intersects with the buffer.
 

GMWolf

aka fel666
I think what we need is the code that resizes the resolution.
does it also resize the light surface?

other issue: It could be creating a surface every step if it thinks the surface doesn't exist.
Make sure you only have one light controller instance. (Or use instance names like the tutorial suggests)

[edit]

right here:
Code:
if (!surface_exists(!obj_Light_Controller.light_surface))
!obj_Light_Controller.light surface? Why is there a '!' ? that is your bug right there.
 
C

Consuming Octorocks

Guest
...Holy hell it was THAT SIMPLE!? Jesus i feel so dumb right now. Thanks for the help and sorry for the troubles everyone. Much appreciated!
 
Top