Expired Object must die!

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
messy
Posts: 7
Joined: Sat Jan 07, 2012 8:02 pm

Expired Object must die!

Post by messy »

Hello,

i have this code in my update method for my "ExpiredObject manager":

Code: Select all

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?
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Expired Object must die!

Post by serengeor »

messy wrote: 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.
Working on game: Marrbles (Currently stopped).
messy
Posts: 7
Joined: Sat Jan 07, 2012 8:02 pm

Re: Expired Object must die!

Post by messy »

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.
messy
Posts: 7
Joined: Sat Jan 07, 2012 8:02 pm

Re: Expired Object must die!

Post by messy »

Ah, it works:

Code: Select all

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?
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Expired Object must die!

Post by serengeor »

Should be enough.
Working on game: Marrbles (Currently stopped).
Post Reply