• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Arrays get corrupted (probably by garbage collector)

Tassadar

Member
TL; DR: arrays in our game randomly get corrupted from time to time (array transforms to empty "[ ])" causing crashes like "Variable Index [4] out of range [0]". And it can be partially fixed by increasing gc_target_frame_time from default 100 microseconds to 1000-2000 microseconds.

Our game has LOTS of arrays and after switching to Gamemaker 2.3 (and adding even more arrays) we start to get this bug. With default gc_target_frame_time array corruption can be rolled sometimes in few seconds after loading a game, sometimes in 20-30 minutes. After changing gc_target_frame_time to 1000 microseconds corruptions become really rare but still can appears sometimes. And looks like increasing from 1000 microseconds to 2000 microseconds does not make the situation better. We've tried to disable GC completely by gc_enable(false) and looks like array corruptions don't appear without GC. But disabling GC is definitely not a solution. Also we've noticed that this bug rolls far more often on weaker PCs. This issue appears in different arrays and we double-checked that nothing could overwrite that corrupted array with "[ ]".

Could anyone help to find a solution to our situation?
 

gnysek

Member
Ooh! That's the bug I'm randomly getting too! I've tried to reproduce it, but it's really random, and takes from 10 seconds to several minutes to happens, usually right before reading from array in some event (which doesn't happens every frame). In my case it was array 20x20, and sometimes one of rows becames []. Minimizing project doesn't help, I've also tried to find what actions causes this, so this bug happens faster, or at least at some regular moment, but I wasn't able to create anything satisfying.

It's at least since closed 2.3.0 beta, that was the only bug which I wasn't able to describe enough, so it can be verified and fixed easily.

I've added this thread to watched.
 

Kezarus

Endless Game Maker
What!? That's my exact bug that almost drove me insane! o_Ô

Here is my thread on this.

After I changed some code that have nothing to do about it the bug suddenly vanishes and I wasn't able to reproduce it even reverting to my old code (but not the entire project). Just when @TsukaYuriko was about to help me I couldn't show her the bug. 😞

I'm also having some VERY crazy silent crashes and it seems it have something to do with arrays. But I really don't know whats causing it because... they are silent crashes... Sometimes it never happens like on 15/Dez when I was programming. Sometimes it happens dozens of times like on 16/Dez. One day difference, little code changed, same functions beign performed. This is maddening...

I would love to pin point and get the exact line where it's happening, but the damn thing keep changing and is inconsistent as it can be... sorry. = /
 

Tassadar

Member
What!? That's my exact bug that almost drove me insane! o_Ô

Here is my thread on this.

After I changed some code that have nothing to do about it the bug suddenly vanishes and I wasn't able to reproduce it even reverting to my old code (but not the entire project). Just when @TsukaYuriko was about to help me I couldn't show her the bug. 😞

I'm also having some VERY crazy silent crashes and it seems it have something to do with arrays. But I really don't know whats causing it because... they are silent crashes... Sometimes it never happens like on 15/Dez when I was programming. Sometimes it happens dozens of times like on 16/Dez. One day difference, little code changed, same functions beign performed. This is maddening...

I would love to pin point and get the exact line where it's happening, but the damn thing keep changing and is inconsistent as it can be... sorry. = /
Thanks for the link. I've read a thread and looks like switching from
GML:
arrBuildings[point[0]][point[1]] = newBuilding;
to
GML:
var coorX = point[0];
var coorY = point[1];
arrBuildings[coorX][coorY] = newBuilding;
worked for you? We also have a lot of code like
GML:
lootlist[recipelist[curcraftid][c_recipeListId]][c_lootListAmount]
switching every similar case to local variables looks like pain but we've already spent few days to find any workaround and if it worked for you probably we should try too
 

gnysek

Member
Three things about my problematic array.
1) it's a global one
2) it got some data loaded from file; first, I'm creating a temporary array using var array = [];, then I'm filling each cell with data, then I'm assigning this array to global by variable_global_set("someglobal", array);, so it's copying from one source to another.
3) I've tried with forcing gc every frame, but that doesn't make bug to appear faster
 
Three things about my problematic array.
1) it's a global one
2) it got some data loaded from file; first, I'm creating a temporary array using var array = [];, then I'm filling each cell with data, then I'm assigning this array to global by variable_global_set("someglobal", array);, so it's copying from one source to another.
3) I've tried with forcing gc every frame, but that doesn't make bug to appear faster
Have you tried using the beta version?I had a similiar issue and they told me that it is fixed in the beta version after sending them the project.
Edit: My issue seems to be resolved after the latest stable update that was pushed an hour ago as well!
 
Last edited:

Kezarus

Endless Game Maker
@Tassadar, the absolute infuriating thing is... it worked just fine the next day. No matter if I switched codes anymore. I didn't had any Steam GMS updates that day.

Maybe after the update of today it solved things. So I advise against any major changes. (at least I wouldn't do it) @Dreamknight, thanks for sharing. Gonna post if I find anything on mine when I got the chance to look properly at it.
 

gnysek

Member
Edit: My issue seems to be resolved after the latest stable update that was pushed an hour ago as well!
No, I didn't yet tested latest release which came this week (beta and stable are now same from what I see), my last tests are from end of November. Seems that I'm going to have a long night today, to test it :)
 

Tassadar

Member
Have you tried using the beta version?I had a similiar issue and they told me that it is fixed in the beta version after sending them the project.
Edit: My issue seems to be resolved after the latest stable update that was pushed an hour ago as well!
Our game still have this crash =(
IDE 2.3.1.542 and runtime 2.3.1.409
We've removed gc_target_frame_time to get more clear test. Maybe crashes are not so often now but the problem is still critical.
 
Just chiming in to say that I've been doing a ton of work with arrays in the latest beta version (v2.3.1.1.248) and I haven't had a single crash (GC enabled the whole time). Not discounting anyone's experience at all, but just adding a data point.
 

Kezarus

Endless Game Maker
So far... I didn't get any issues and I have the same version as you, @Tassadar (heh, lots of StarCraft vibes with that name).

Last day or two I was creating an A* algo that uses a little array on the side.

The other code that was causing trouble is running too and the bug seems to be squashed now. At least on my side.

@RefresherTowel, hmmm, it seems that beta and stable have some differences then. Good to know.
 

FrostyCat

Redemption Seeker
Just chiming in to say that I've been doing a ton of work with arrays in the latest beta version (v2.3.1.1.248) and I haven't had a single crash (GC enabled the whole time). Not discounting anyone's experience at all, but just adding a data point.
Chiaroscuro was a pre-2.3 project with arrays but no structs, yet it has been crashing after as little as 1 game on YYC. The GC seems to have trouble coping with missing the target time set by gc_target_frame_time, which happens more readily under crush loads like the kinds generated by tree search algorithms.

Update: I've turned off automatic GC and manually called gc_collect() at the end of every tree expansion. This lasted more than 5 games without crashing, and also without significant leakage as viewed from Task Manager. While the bug is still significant, for intensive usage this seems to be a viable workaround for now.
 
Last edited:

Tassadar

Member
Chiaroscuro was a pre-2.3 project with arrays but no structs, yet it has been crashing after as little as 1 game on YYC. The GC seems to have trouble coping with missing the target time set by gc_target_frame_time, which happens more readily under crush loads like the kinds generated by tree search algorithms.

Update: I've turned off automatic GC and manually called gc_collect() at the end of every tree expansion. This lasted more than 5 games without crashing, and also without significant leakage as viewed from Task Manager. While the bug is still significant, for intensive usage this seems to be a viable workaround for now.
Looks like gc_enable(false) and adding gc_collect() every step works fine like workaround. Also setting gc_target_frame_time(1000000) works for us. I was afraid of big lags every step but everything seems fine for now.
 
Top