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

Windows memory leak on layer_exists/layer_tilemap_exists

jonjons

Member
hello
ive set a presistent object, to create a tile_layer on all levels
creat event
Code:
mp1_layer = layer_create(-1000);
mp1_tile = layer_tilemap_create(mp1_layer, 0, 0, tl_mp1, 60, 34);
step event
Code:
if ( ! layer_exists( mp1_layer ))
    {
        mp1_layer = layer_create(-1000);
    }

if ( ! layer_tilemap_exists(mp1_layer, tl_mp1) )
    {
        mp1_tile = layer_tilemap_create(mp1_layer, 0, 0, tl_mp1, 260, 234);
    }
draw_gui event
Code:
if ( mouse_check_button( mb_left ) )
{
    tilemap_set_at_pixel(mp1_tile, 3, mouse_x, mouse_y)
}
but it seems the layers are getting created infinite times.
Is there a way to use the functions layer_exists/layer_tilemap_exists, to only create the layers 1 time ?
or
to manually set a tile_layer in each level and draw the tiles on that layer, with mouse press ?
 

sylvain_l

Member
you can work on any room with:
https://docs2.yoyogames.com/source/...rence/rooms/layers/layer_set_target_room.html

edit:
are you saying your code create layer in an infinite loop (every step) ?

or do you mean it create a new layer every time you change a room (which is what it is meant to do as it is coded! )
I mean every time you go back to a room you already went. Because everytime you overwrite the id of the layer from the room you leave (as it's not in the new room, with a new id layer so loss the ref to all the previously created layer id!! so yeh you got a leak here.
you need to use layer_destroy(layer_id) when you leave your room; or you need to keep a map of all the layer created for each levels.
 
Last edited:

jonjons

Member
you can work on any room with:
https://docs2.yoyogames.com/source/...rence/rooms/layers/layer_set_target_room.html

edit:
are you saying your code create layer in an infinite loop (every step) ?

or do you mean it create a new layer every time you change a room (which is what it is meant to do as it is coded! )
I mean every time you go back to a room you already went. Because everytime you overwrite the id of the layer from the room you leave (as it's not in the new room, with a new id layer so loss the ref to all the previously created layer id!! so yeh you got a leak here.
you need to use layer_destroy(layer_id) when you leave your room; or you need to keep a map of all the layer created for each levels.
yeah i notice the layer_id must be used when created a layer throw code
but i cant understand whats going on ?
it happens right in the 1st room without changing to the next one...

Ive instantiated an instance in each ( ! layer_exist )
if ( ! layer_exists( mp1_layer ))
{
mp1_layer = layer_create(-1000);
instance_create_depth(100, 100, -100, obj_null);
}

if ( ! layer_tilemap_exists(mp1_layer, tl_mp1) )
{
mp1_tile = layer_tilemap_create(mp1_layer, 0, 0, tl_mp1, 260, 234);
instance_create_depth(100, 100, -100, obj_null);
}

the instance_count is not increasing stops at 5, but the memory drops out really fast
 

sylvain_l

Member
feels like perhaps your layer system isn't the current source of leak.
the instance_count is not increasing stops at 5, but the memory drops out really fast
any other creation (sprite, surface, etc...) ? - we already know it's not instances as the number stay stable at 5.
search for the word "create" in your project, to track down if one is linked to creation of anything in step or loop that could be source of a reccurent creation that leed to the leak
 

jonjons

Member
the "create" words ive found were most related with instance_create/ds_grid create in the project.

ive tried another solution
making a tile_set layer in the room "layer_mp1"

then in the object step event
Code:
tl1 = layer_get_id("layer_mp1");
tl2 = layer_tilemap_get_id(tl1);

if ( mouse_check_button( mb_left ) )
{
    tilemap_set_at_pixel(tl2, 2, mouse_x, mouse_y);
}
ive followed mostly whats on the help manual
but with no luck the tiles arent being draw in screen on the mouse press

[edit]
also used in the gui event
draw_text(100, 100, tl1);
draw_text(100, 120, tl2);

both return -1
 
Top