I declare
boost::unordered_map<int, GameObject*> gameObjects
So i can do:
gameObjects[obj.id] = obj
obj = gameObjects[id for some obj i want]
And everything worked great when i was just adding stuff and game objects was not killed.
But now for every frame, i iterate an unordered_map X containing pointers to all objects that are relevant for updating:
Loop()
- Update X
- - iterate objects and update states
- Remove objects that are dead in X
- - put pointers to objects marked for removal in zombie list (the objects will be deleted later in looping zombie list)
- - erase object (pointer) in X so that it will not be considered for update next time.
The problem is that if in Removal part i do X.erase(obj with id 6) then the next time it does Update X it still iterates over it
iterator->first = 6
iterator->second = INVALID (the game object)

Why does it keep the key and considers it for iteration when the element was erased?
