Hi,
The problem is that if im in the loop, and a method in this loop remove an element from the vector, the program crashes, an example:
for (std::vector<Enemy*>::iterator it = GameObjects::enemies->begin(); it!=GameObjects::enemies->end(); ++it) {
((Enemy*)*it)->update();
}
The update check the collision and call remove method:
if (Collision::PixelPerfectTest(sprite, GameObjects::planet->getSprite()))
{
GameObjects::enemies->erase(std::find(GameObjects::enemies->begin(), GameObjects::enemies->end(), this));
}
When ERASE method is called, the program crashes.