Closed Jie-F closed 6 months ago
Oops, missed that this same bug happens in the other loops for mine-asteroid and ship-asteroid collisions too. As a fix, I'll just change over the entire asteroid culling to do one list comprehension at the end, and collect and check deleted asteroid indices along the way. This will fix the bug, along with speeding up asteroid culling.
In the update() loop when checking asteroid-bullet collisions, after an asteroid collides with a bullet, the asteroid can go on to collide with more bullets in subsequent loop iterations, and each time it collides, it spawns off 3 new children.
To fix this, we can add the following check, so that asteroids marked for removal cannot go on to collide with more bullets:
And as a possible optimization, we can actually just cull the asteroids once at the end of update(), and along the way just skip over indices that are marked for removal. That's what I'm doing in my controller to reduce the amount of list comprehensions.
Super sneaky bug that I only found with randomized testing, where my controller using different collision code desynced with the game for seemingly no reason.