hakase-labs / hikari

Mega Man/Rockman game clone written by nerds for nerds.
43 stars 8 forks source link

Removing game objects crashes the game #231

Closed zackthehuman closed 9 years ago

zackthehuman commented 9 years ago

If you try to remove a game object that isn't actually owned by the GameWorld it will crash. Seems like it crashes while processing the removal queue.

zackthehuman commented 9 years ago

The issue is that the end iterator is not being passed in when using the erase/remove idiom in GameWorld. This code:

activeEnemies.erase(
    std::remove(std::begin(activeEnemies), std::end(activeEnemies), objectToBeRemoved));

Should really look like this:

activeEnemies.erase(
    std::remove(std::begin(activeEnemies), std::end(activeEnemies), objectToBeRemoved),
    std::end(activeEnemies)
);

Otherwise we're matching the wrong signature of erase. I don't know how this was ever working :-1: