for(it = gameObjects.begin();it!=gameObjects.end();it++){
it->second->update(frameTime);
if(it->second->getSprite()->GetPosition().y > 500){
std::cout << "Removing enemy" << std::endl;
std::map<sf::String,VisibleGameObject*>::iterator itor = Remove(it->second->getName());
if(itor!=gameObjects.end()){
std::cout << "itor doesn't equal" << std::endl;
it=itor;
}else{
std::cout << "itor = end" << std::endl;
it=itor;
}
}
}
As soon as itor = end is printed, it errors - "map set iterator not incrementable". I thought the for loop should end before it increments again, as it!=gameObjects.end() will be false after this. Adding a break in the else statement resolves the problem.
Why doesn't it work without the break? I'm assuming it's something to do with when the iterator is incremented compared to when the condition is checked.