• 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!

Possible Memory leak (solved)

Roastedzerg

Member
Hey gmc, Ive been having some lag issues in my game with vsync turned on (turning it off creates lots of tearing in the game, but it runs alot smoother with only a little lag) And i think it might be the priority queues i have set up in each enemy object to search for the player. Im sure its because there are multiple queues being made in one room, but thats what i had to do to make each enemy have their own mind instead of a hive mind.
Does anyone see anything in the following code that could be causing a huge drop in frames?
Code:
//Clear priority every step
ds_priority_clear(player_list)
//Add to enemy_list if we see a player
var i;
for(i=0;i<instance_number(obj_player_parent);i++)
{
    global.player[i]=instance_find(obj_player_parent,i);
    if(!x_ray_vision)
    {
        if(!collision_line(x,y,global.player[i].x,global.player[i].y,obj_block,false,true))
        {
            ds_priority_add(player_list,global.player[i].id,point_distance(x,y,global.player[i].x,global.player[i].y));
        }
    }
    else
    {
        ds_priority_add(player_list,global.player[i].id,point_distance(x,y,global.player[i].x,global.player[i].y));
    }
}
//Set our target
if(ds_priority_empty(player_list))
{
    my_target=noone;
}
else
{
    my_target=ds_priority_find_min(player_list);
}

FYI i am indeed destroying the queue when the enemy object is destroyed



EDIT: Hmm just tried making it into an executable and it doesnt lag at all. only when im working on it in the IDE. Is this just a problem with GMS2?
 
Last edited:

Roastedzerg

Member
Really? Everywhere i looked people said lag could be because of a memory leak. Mind elaborating for me? Im no expert.
 

obscene

Member
Lag = Delay caused by internet connection.
Low FPS = Slowdown of game caused by code and/or drawing
Memory Leak = Your application size is getting larger and larger in memory until windows tells you it's out of available memory.

If you want to know if you have a memory leak, look at the debugger memory usage and see if the graph continually rises.

If you're getting low FPS, use the debugger profiler and see what's taking the most resources. Could be a large number of objects running heavy code. Most likely drawing. Many ways to improve it but you have to know the source of the issue first.
 
Last edited:
Top