Game inconsistently crashes. What does local_vector.h do?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bupintong

Context: Our game has a lot of enemies on screen (think of Vampire Survivors), so there’s a lot area2Ds / Kinematic Bodies with collisions colliding with each other.

The crash happens with the following steps:

  • Spawn a bunch of enemies
  • Kill them with an AOE spell (not sure if this is the problem or it just increases chances for the crash since it kills more faster)
  • Eventually (it can take less than a minute or 15) the game will crash leaving the following report in the logs (p_index can change it’s value between crashes):

ERROR: FATAL: Index p_index = 4 is out of bounds (count = 0). at: operator[] (./core/local_vector.h:181) - FATAL: Index p_index = 4 is out of bounds (count = 0).

We actually managed to reproduce this Fatal error in a new project, and posted an issue about it. But a new problem has arised: we tried backing to 3.4 since in the issue we found out it doesn’t occur in 3.4, this version of the game is really bugged, since it was a quick test all the Scene Unique Nodes and Tween changes between 3.4 and 3.5 were just commented (i’m saying this in the offchance that all the errors related to commenting those parts of the code may be causing the crash in 3.4). In this version we started trying the crash again, it was hard but we found it again (and this time the console log displayed the error instead of the file hidden in %appdata%)

So now there’s a new problem, in the issue we found out freeing large quantities of colliding Area2Ds crashes the game, if instead of freeing we just disable / stop monitoring then the small test we made doesn’t crash. Then why does it happen in our big project?

To recreate this disable / monitoring off behaviour efficiently we started pooling the enemies, but it still crashes. So now we can’t really know what the problem is, it may be a combination of nodes colliding and then stop colliding, it may be a caching problem, it may be a file corrupted.

With all this, we would like to know: What does local_vector.h do? and what does it have to do with Area2Ds / KinematicBodies / CollisionBoxes? if anyone knows please tell us.

Also running into this issue. I managed to remove most area 2Ds that I believe were the cause, but this really needs a fix.

cardboardboxentmt | 2022-11-25 01:39

I think we might have fixed it, we used set_deferred to disable / stop monitoring for every Area2D / CollisionBox before freeing them and it looks like this avoids the issue, we are still testing it but it hasn’t crashed yet.

Bupintong | 2022-11-25 02:12

Thanks for the heads up. I’ve also done some looking into this and I tend to hit it when area2ds are being spawned while doing a shape query. It is fairly inconsistent during normal play, but I’ve managed solid repros in some testbeds spawning hundreds of area2ds during a check.

I can find a workaround for now, but I’ll have to basically write my own overlap checking scripts until its fixed for real.

cardboardboxentmt | 2022-11-29 07:57

https://www.youtube.com/watch?v=60895AGpKAo

cardboardboxentmt | 2022-11-29 08:01