for(list<ExpiringObject>::Iterator it = expiringObjects->begin(); it != expiringObjects->end(); it++)
{
if (it->isExpired())
{
// have to die!
}
else
it->update(frameDeltaTime);
}
I want to delete the object if its time is come, but all my tries run in program crashes. Can someone help me?
Hardly, with the code fragment provided we can only guess what is wrong.
My first guess is that you are deleting the object and not removing it from the list. Second guess is that you are deleting an object which should not be deleted, because it is used somewhere else.
This code fragment is all in my method. This method is calling on each frame. expringObject is a list with objects which have a Boolean that set on true after 5 seconds. This is the moment where isExpired() is true. Now i want to delete it from the list. I have used erased(it), but i doesn't work. It is not used somewhere else.
bool ObjectFactory::update(f32 frameDeltaTime)
{
for(list<ExpiringObject*>::Iterator it = expiringObjects.begin(); it != expiringObjects.end(); )
{
if ((*it)->isExpired())
{
delete(*it);
it = expiringObjects.erase(it);
}
else
{
(*it)->update(frameDeltaTime);
it++;
}
}
return true;
}
In ExpiringObject gives it a pointer to a ISceneNode. This node should be deleted too. Therefore in the destructor of ExpiringObject i call node->remove(). Is it enough to delete everything?