Sorry, I forgot to remove the
#include "LinkedList.h" line right near the top.
Just remove that and it should work.
As in add more entries, or add entries that are unlocked as the game progresses?
Both can have the menu data stored in an immutable way, the latter would just require a way to track which entries are visible, like a bit vector or just an index specifying how many should be visible (if they’re unlocked sequentially).
I’ve identified the bug. Without meaning to gloat, I’m happy to report it’s not my fault.
The problem is in
explosions.removeAt(i); is called, the
continue takes the code back to the
enemies loop, but not the
explosions loop, which means
i < explosions.getCount() isn’t re-checked, and in the case that
explosions.removeAt(i) has caused
explosions to become empty,
i will refer to an invalid item and the next call to
removeAt will try to remove a nonexistant object, which will subsequently fail.
The best way to solve this is to check that
i is still valid after calling
removeAt, and take that as a cue to exit the outer loop. I like this solution because it avoids extra work.
Originally I had some
assert functions in
removeAt that would have detected this problem and reported it, but I commented them out when I tore the file out of the library it was originally a part of because I assumed it wouldn’t be necessary to bring them along.
This is a logic error with the calling code, hence it should break in a loud and nasty way.
Silently consuming the error would just be setting the calling code up for further failures, as well as being less efficient because of the extra checking.
I think a good solution would be:
That fixes the explosion, but there’s a similar error elsewhere that needs to be tracked down.
I think I’ve found the other problem in
//enemies[z].dead = true;
//Serial.println("Enemies remaining: " + (String)enemies.getCount());
I figured it would be in a similar
NxM loop that was attempting two
removeAts in quick succession.
Sure enough that seems to have fixed the problem.
Now there are explosions everywhere without a reset in sight.