Custom Scene Node Example Question [Solved]

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
geckoman
Posts: 143
Joined: Thu Nov 27, 2008 11:05 am
Location: Germany
Contact:

Custom Scene Node Example Question [Solved]

Post by geckoman »

In the Custom Scene Node Example I understand almost all of it but the following:

Line 199 ff:

Code: Select all

	// Because the new node will create itself with a reference count of 1, and
	// then will have another reference added by its parent scene node when it is
	// added to the scene, I need to drop my reference to it.  Best practice is
	// to drop it only *after* I have finished using it, regardless of what the
	// reference count of the object is after creation.
and this:

line 219

Code: Select all

		// I'm done referring to anim, so must drop this reference now because it
		// was produced by a createFoo() function.
		anim->drop();
		anim = 0; // As I shouldn't refer to it again, ensure that I can't
Can anybody explain that to me? What is this reference count, where is it stored, who set it to 1, and WHY can't I have another ref. to it?

Probably this is more coding related than Irrlicht specific, but I don't know.
Last edited by geckoman on Fri Dec 12, 2008 11:41 am, edited 1 time in total.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

he reference count is basically a count of how many parts of your app are using that node and want it to be valid. For example the scene manager will store a pointer to it and you may store a pointer to it in your code and maybe use it in more than one place so you can prevent it from being deleted until the reference count is 0, i.e. no one needs it anymore.

if you deleted the node yourself and the scene manager still thought it would valid that would cause a crash as the scene manager would dereference its pointer to the node but as it's been deleted it's now invalid.

ISceneNode inherits from IReferenceCounted as can be seen here: http://irrlicht.sourceforge.net/docu/cl ... _node.html

Anything inheriting from IReferenceCounted will have a reference count and upon creation the reference count will be set to 1 by the IReferenceCounted constructor.
Image Image Image
geckoman
Posts: 143
Joined: Thu Nov 27, 2008 11:05 am
Location: Germany
Contact:

Post by geckoman »

Ahhhhhh thank you very much! Now I understand it fully!!!
:D
Katsankat
Posts: 178
Joined: Sun Mar 12, 2006 4:15 am
Contact:

Post by Katsankat »

Hi,
I got a question on this topic: is there a list somewhere of what must be dropped?

scene::IAnimatedMesh*
scene::ISceneNodeAnimator*
scene::ITriangleSelector*

... Are there others?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

All objects returned by create...() methods.
Post Reply