Weird access violation error with stack
In my game, I have this piece of code:
I used some ghetto-style debugging. This game library does not have a debug build, so I cannot step-through. What I did was have it write to a text file every couple lines to narrow it down (not shown obviously). It errors out right before the SpawnEnemy call.
Game::isSpawned = false;
level.setCurrentLevel(level.getCurrentLevel() + 1);
It does not even get to the first line of the actually SpawnEnemy function. Enemy_Knight is simply an integer enumerator. EnemiesToSpawn is a stack of ints. There is nothing else it could be except for the stack.
What's weird is I will get an access violation error RANDOMLY. It's always on this line, but it occurs anywhere from 2-10 minutes of game play. I don't get why it does this - what exactly would cause an error like this? I would think it would maybe occur if the stack is empty when I tried to top() it, but the if statement is clear and straightforward - that can't be the case.