Deleting a game object causing an access violation
- by Balls
I tried doing this but it cause an access violation.
void GameObjectFactory::Update()
{
for( std::list<GameObject*>::iterator it=gameObjectList.begin() .....
(*it)->Update();
}
void Bomb::Update()
{
if( time == 2.0f )
{
gameObjectFactory->Remove( this );
}
}
void GameObjectFactory::Remove( ... )
{
gameObjectList.remove( ... );
}
My thoughts would be to mark the object to be dead then let the factory handle it the on next frame for deletion. Is it the best and fastest way? What do you think?