GMS 2 Iterating through DS List Works when Debugging only [Solved]

Animus570

Member
I have encountered a bug in my code when I attempt to iterate over a ds_list containing objects returned from a json file. When the application runs normally this error appears, as well as when I debug the code and hit F5 to move to the break point after the for loop (the error on line 23 corresponds to line 6 of the snippet). However, when I step through the loop manually while debugging no exception occurs. After stepping through the for loop I can hit F5 to begin normal execution of the program and no error occurs.

If someone could point me in the right direction on how I would go about solving this issue that would make life much easier.

############################################################################################
ERROR in
action number 1
of Create Event
for object objSetup:

Data structure with index does not exist.
at gml_Object_objSetup_Create_0 (line 23) - var enemy = enemyDataCollectionDsList[| i];
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_objSetup_Create_0 (line 23)

Code:
var enemyCollectionDsMap = ReadJsonFile("enemies.json");
var enemyDataCollectionDsList = enemyCollectionDsMap[? "enemies"];
var mapCount = ds_list_size(enemyDataCollectionDsList);

for (var i = 0; i < mapCount; i++)
{
    var enemy = enemyDataCollectionDsList[| i];
    instance_create_depth(real(enemy[? "x"]), real(enemy[? "y"]), real(enemy[? "layer"]), objButterfly);
    ds_list_destroy(enemy);
}

ds_map_destroy(enemyCollectionDsMap);
ds_list_destroy(enemyDataCollectionDsList)
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
It would appear that "enemy" is a ds_map, but then you use it with ds_list_destroy, thus destroying some unrelated list (if any) with same ID
 

Animus570

Member
It would appear that "enemy" is a ds_map, but then you use it with ds_list_destroy, thus destroying some unrelated list (if any) with same ID
That is an oversight on my part, I have changed the code and things are behaving as expected.
It is very odd that this was not an issue when stepping through the code though.

I appreciate the quick response, as a professional developers the idiosyncrasies of GML can throw me at time.
 
Top