Another about when deleting.

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
Vsk
Posts: 343
Joined: Thu Sep 27, 2007 4:43 pm

Another about when deleting.

Post by Vsk »

I know this has been asked, and I have red the posts.
But I have a litllte doubt.

When we are adding animators to a node either the animator is created by me or a defual animator from irrlicht, should I drop them /delete them?
Or because the fuction has an "add" at the beggining is will handle it?

In practice, I have:

particleSystem->addAnimator(new MyAnimator);
and I have too:
partileSystem->addAnimtor(smgr->createDeleteAnimtor);

this way will generate any memory leaks? or because is it and "add" function it will call the corresponding "delete" for each one before it got destructed?

Thanks.
radiant
Posts: 112
Joined: Fri Feb 22, 2008 8:04 pm
Location: Mexico

Post by radiant »

what u have to do is this:

Code: Select all

ISceneNodeAnimator* myAnimator=smgr->createDeleteAnimator(u32 timeMs);
//this animator will delete the scene node its atached to...more like set invisible

mySceneNode->addAnimator(myAnimator);
//this attatch the animator to a scene node(camera, mesh, light or whatever)
myAnimator->drop();
//this will delete the animator... it has to be called cause it was created with a 
//create method
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Not sure what your comments are on about there... I don't believe the delete animator sets a node to invisible, it actually deletes it...

And drop would not delete the animator in that case, just reduce its reference count so that when the node is done with it (i.e. after timeMs countdown) it then gets deleted safely.
Image Image Image
Vsk
Posts: 343
Joined: Thu Sep 27, 2007 4:43 pm

Post by Vsk »

Thanks both, but I don'¡t know understand finaly what to do.

The thing is that I have tow kind of animators
-The one created by me (inherited from where it should, don't remember who now :P).

-The one that are already for default in irrlicht api.

So, if understend well both of you, instead of doing this:

Code: Select all

particleSystem->addAnimator(new MyAnimator);
and I have too:
partileSystem->addAnimtor(smgr->createDeleteAnimtor); 
I should do this right?:

Code: Select all

ISceneNodeAnamitor * myA = new MyAnimaotr(...);
particleSystem->addAnimator(myA);
myA->drop;


ISceneNodeAnamitor * defaultIrrlichtA = smgr->createdDeleteAnimator();
particleSystem->addAnimator(defaltIrrlichtA);
defaultIrrlichtA->drop;
It is correct?
So, in this way do I have garanted that when "myA" is not used no more, its delete operator will be call automaticly?
I am worry casue I am having ungle memory lost :(.

Thanks again.
radiant
Posts: 112
Joined: Fri Feb 22, 2008 8:04 pm
Location: Mexico

Post by radiant »

about the.. DeleteAnimator thing... i was just guessing... cause...i havent worked with this one yet... and it seemed a little... haky to use an animator to remove a scene node when u can actually remove it when the time comes....

and about the ->drop thing... thats what i meant... but for the look of what he asked it seemed easyer to understand what i said that what u said... taking that it wasnt clear afther reading other posts about this...

in both cases... my bad

Anyway u should check the Api doc included with the engine (this one is to Vsk) look for ISceneNodeAnimator class in the api and

ISceneManager::add<some circle, line, delete or whatever>animator()

it should give u enough info about when do delete an animator ( or any other thing created with a create<something>() method)

I hope i cleared my thoughs on this
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Code: Select all

ISceneNodeAnamitor * myA = new MyAnimaotr(...); 
particleSystem->addAnimator(myA); 
myA->drop; 

ISceneNodeAnamitor * defaultIrrlichtA = smgr->createdDeleteAnimator(); 
particleSystem->addAnimator(defaltIrrlichtA); 
defaultIrrlichtA->drop; 
It is correct?
Yes, this is correct except for the missing parens on the drop calls. You should write myA->drop() because you are calling the function.
So, in this way do I have garanted that when "myA" is not used no more, its delete operator will be call automaticly?
Yes. This properly decrements the reference count. The rule is that if you call createXXX() or a new expression [new MyThing] to make an object, then you need to call drop() on it when you're done. Any other code that wants to use the object should call grab() when they want to make sure it isn't deleted, and then drop() when they are done.

Travis
Vsk
Posts: 343
Joined: Thu Sep 27, 2007 4:43 pm

Post by Vsk »

Thanks.
Yes, I forgogt the parenthesis.
Post Reply