Solitary Confinement
Member
Heya,
So I have a series of global grids to which I add rows, and delete rows by resizing the grid. The adding is done by a script which uses the name of the global grid to which entries must be added. My problem is, if I keep adding, then resizing the grid (to simulate row deletion), I eventually get a memory allocation error, specifically at the grid resizing part. Note that the global grids are never meant to be destroyed at any time.
Relevant code for a cursor object that adds entries to a target global grid (global.grid_ext_b[0] in this case):
Step event (the only real relevant parts here are the script call for scr_grid_set_player and ds_grid_resize):
The adding to grid script (scr_grid_set_player):
I'm aware of the need for manually deleting local vars containing data structures since GMS lacks the garbage collection needed for this. However, when I tried the following in the above script:
The script then throws a "Data structure with index does not exist." error.
I'm probably doing this the wrong way. Could someone help point out the correct approach?
Thanks in advance.
So I have a series of global grids to which I add rows, and delete rows by resizing the grid. The adding is done by a script which uses the name of the global grid to which entries must be added. My problem is, if I keep adding, then resizing the grid (to simulate row deletion), I eventually get a memory allocation error, specifically at the grid resizing part. Note that the global grids are never meant to be destroyed at any time.
Relevant code for a cursor object that adds entries to a target global grid (global.grid_ext_b[0] in this case):
Step event (the only real relevant parts here are the script call for scr_grid_set_player and ds_grid_resize):
GML:
if myid.team_phase == 1
{
if type == 0 //SELECTOR
{
if complete_selection != true
{
if keyboard_check_pressed(global.k_lt) //add selection
{
if avail == true
{
if can_ent == true
{
can_ent = false
alarm[5] = can_ent_rt
scr_snd_cre_obj(global.snd_menu_enter)
if myid.arc_pool_blue_curr < global.pool_slots_blue_1
{
if myid.arc_pool_blue_curr == 0
{global.player_a_t = myid.crs.targ}
myid.arc_pool_blue_curr += 1
var t_crs = myid.crs.targ //Refer to SELECTOR's targ
//*add to *grid
ds_list_add(global.pool_list_blue_1,
global.ar_arc[t_crs, 0]
)
//ADDING PART
scr_grid_set_player(myid.crs_team, global.grid_ext_b[0])
}
with (myid.crs_team)
{
if x_pos < (global.solo_team_max - 1)
{
//add selection
base_t.t = myid.crs.targ
//move forward
x += myid.grid_dist_x
x_pos += 1
}
else if x_pos == (global.solo_team_max - 1)
{
//final selection - add, but don't move forward
base_t.t = myid.crs.targ
global.nextroom = room_arc_ladder
alarm[2] = delay //delay, then room ladder
complete_selection = true
allow = 0
with(myid.crs) {allow = 0; complete_selection = true}
}
}
}
}
}
else if keyboard_check_pressed(global.k_hv) //roll-back selection
{
if can_ent == true
{
can_ent = false
alarm[5] = can_ent_rt
with (myid.crs_team)
{
//roll back
scr_snd_cre_obj(global.snd_menu_arc_desel)
if base_t.t > - 1//x_pos >= 0
{
ds_list_delete(global.pool_list_blue_1,
x_pos
)
myid.arc_pool_blue_curr -= 1
base_t.t = - 1
//*DELETING PART// remove / *delete from grid
//var grid_ext = global.grid_ext_b[0]; <-- local var can lead to pointer being missed, causing memory allocation error
ds_grid_resize(global.grid_ext_b[0], ds_grid_width(global.grid_ext_b[0]), ds_grid_height(global.grid_ext_b[0]) - 1)
The adding to grid script (scr_grid_set_player):
Code:
//Add to grid by players' actions, namely in char select screens
/// @param adding_cursor
/// @param grid_ext[x]
var adding_crs = argument[0] // //Refer to cursor that's being used to add chars to the grid. Can be myid.crs_team or myid.crs only, depending on game mode
var grid_ext = argument[1] //the target grid, global.grid_ext_b[0] e.g.
//add additional args later
if global.gmode == "solo"
{
var solo_pos = 0
ds_grid_resize(grid_ext, ds_grid_width(grid_ext), solo_pos + 1);
ds_grid_set(grid_ext, 0, solo_pos, myid.crs.targ) //t value
ds_grid_set(grid_ext, 1, solo_pos, global.ar_arc[myid.crs.targ, ar_arc.name_add]) //name "g90" e.g.
ds_grid_set(grid_ext, 2, solo_pos, global.ar_arc[myid.crs.targ, ar_arc.rank]) //rank
ds_grid_set(grid_ext, 3, solo_pos, 0) //pal indx
ds_grid_set(grid_ext, 4, solo_pos, 0) //pal spr
ds_grid_set(grid_ext, 5, solo_pos, 0) //pool - adjust in accordance to currently selected pool for which chars being added - case switch may be needed
ds_grid_set(grid_ext, 6, solo_pos, solo_pos) //slot
ds_grid_set(grid_ext, 7, solo_pos, "player") //control type
ds_grid_set(grid_ext, 8, solo_pos, 0) //player#
}
else
{
ds_grid_resize(grid_ext, ds_grid_width(grid_ext), adding_crs.x_pos + 1);
ds_grid_set(grid_ext, 0, adding_crs.x_pos, myid.crs.targ) //t value
ds_grid_set(grid_ext, 1, adding_crs.x_pos, global.ar_arc[myid.crs.targ, ar_arc.name_add]) //name "g90" e.g.
ds_grid_set(grid_ext, 2, adding_crs.x_pos, global.ar_arc[myid.crs.targ, ar_arc.rank]) //rank
ds_grid_set(grid_ext, 3, adding_crs.x_pos, 0) //pal indx
ds_grid_set(grid_ext, 4, adding_crs.x_pos, 0) //pal spr
ds_grid_set(grid_ext, 5, adding_crs.x_pos, 0) //pool - adjust in accordance to currently selected pool for which chars being added - case switch may be needed
ds_grid_set(grid_ext, 6, adding_crs.x_pos, adding_crs.x_pos) //slot
ds_grid_set(grid_ext, 7, adding_crs.x_pos, "player") //control type
ds_grid_set(grid_ext, 8, adding_crs.x_pos, 0) //player#
}
Code:
var adding_crs = argument[0] // //Refer to cursor that's being used to add chars to the grid. Can be myid.crs_team or myid.crs only, depending on game mode
var grid_ext = argument[1] //the target grid, global.grid_ext_b[0] e.g.
//add additional args later
if ds_exists(grid_ext, ds_type_grid)
{
if global.gmode == "solo"
{
var solo_pos = 0
ds_grid_resize(grid_ext, ds_grid_width(grid_ext), solo_pos + 1);
ds_grid_set(grid_ext, 0, solo_pos, myid.crs.targ) //t value
ds_grid_set(grid_ext, 1, solo_pos, global.ar_arc[myid.crs.targ, ar_arc.name_add]) //name "g90" e.g.
ds_grid_set(grid_ext, 2, solo_pos, global.ar_arc[myid.crs.targ, ar_arc.rank]) //rank
ds_grid_set(grid_ext, 3, solo_pos, 0) //pal indx
ds_grid_set(grid_ext, 4, solo_pos, 0) //pal spr
ds_grid_set(grid_ext, 5, solo_pos, 0) //pool - adjust in accordance to currently selected pool for which chars being added - case switch may be needed
ds_grid_set(grid_ext, 6, solo_pos, solo_pos) //slot
ds_grid_set(grid_ext, 7, solo_pos, "player") //control type
ds_grid_set(grid_ext, 8, solo_pos, 0) //player#
}
else
{
ds_grid_resize(grid_ext, ds_grid_width(grid_ext), adding_crs.x_pos + 1);
ds_grid_set(grid_ext, 0, adding_crs.x_pos, myid.crs.targ) //t value
ds_grid_set(grid_ext, 1, adding_crs.x_pos, global.ar_arc[myid.crs.targ, ar_arc.name_add]) //name "g90" e.g.
ds_grid_set(grid_ext, 2, adding_crs.x_pos, global.ar_arc[myid.crs.targ, ar_arc.rank]) //rank
ds_grid_set(grid_ext, 3, adding_crs.x_pos, 0) //pal indx
ds_grid_set(grid_ext, 4, adding_crs.x_pos, 0) //pal spr
ds_grid_set(grid_ext, 5, adding_crs.x_pos, 0) //pool - adjust in accordance to currently selected pool for which chars being added - case switch may be needed
ds_grid_set(grid_ext, 6, adding_crs.x_pos, adding_crs.x_pos) //slot
ds_grid_set(grid_ext, 7, adding_crs.x_pos, "player") //control type
ds_grid_set(grid_ext, 8, adding_crs.x_pos, 0) //player#
}
ds_grid_destroy(grid_ext)
grid_ext = undefined;
}
I'm probably doing this the wrong way. Could someone help point out the correct approach?
Thanks in advance.
Last edited: