Weird … here’s my setup: https://gist.github.com/RonJeffries/852904b3ea1e2b74354e
as you can see, it clears the FlyingObjects and Ships lists. Then it creates two ships and adds them. It also creates a sun and puts it in FlyingObjects. I’ve changed the code so that after the main draw, it deletes from Deletes and adds from Adds.
It’s also printing the table (id) and ship.name. (Ship.name is “Ship” + the x value of its color, so they wind up being Ship15 and Ship255. )
After a few runs I got the explosion on startup. Checking a trace of what collided, there was a ship15 colliding with another ship15. The index of one of them was (tada!) from a previous game.
In https://gist.github.com/RonJeffries/1798acf92f27730bfa23 we see the relevant code for collisions (in the Ship class). It loops through Ships (there are two Ships, remember) and does not try to collide with itself. (The double checking is a belt and suspenders left over, but it does never collide a ship with itself.)
Presently the first ship to notice collision removes itself. I expected the second guy to detect the collision as well but for some reason it does not. Since the first ship is not removed until the draw is over, it should still be there. However, it will have moved (the move completes, so that’s probably it. Anyway not germane to the bug.
We see that if the ship collides, it will add an Explosion and delete itself. Finally, in https://gist.github.com/RonJeffries/ec0c59bff34645670496 we see how it deletes old dead guys and adds in the new (explosions are added here, and missiles (not shown)).
Anyway, all this is more for reassurance than anything else. The fact from the printout is that the program is seeing a Ship that was created in a previous call to setup() and as far as I can tell it cannot possibly be in the tables because they are set to {}.
Makes me wonder if just calling setup() is really a safe way to restart the program … and I still don’t know where the bug is. I’ll do more when my battery recharges.
Ideas still welcome!