Hi Ku,

I had an idea : might inheritance interfere with the osg::Referenced system? I 
mean, if I create my own class derived from PAT, then put it in a ref_ptr, will 
it be handled correctly?

No, it should work well as long as you follow the rules... see below.

'cause I've found out the following behaviour :


class CustomPAT : public osg::PositionAttitudeTransform {...}

int main()
{
PositionAttitudeTransform* myPAT1 = new PositionAttitudeTransform();
delete myPAT1; // Compilation error ->  normal

CustomPAT* myPAT2 = new CustomPAT();
delete myPAT2; // Compilation OK !!! ->  shouldn't be
}

Your CustomPAT class probably does not declare a destructor. This means the compiler generates one for you, and it will be public, which is why you can delete myPAT2. Create a destructor and make it protected, even if it doesn't do anything. This is important, otherwise as you saw users can do things that are not good...

I don't know what to think about it... Could it cause a custom class not to be 
handled as it should be?...

No, that specifically should not cause ref_ptr to not delete your custom class when it needs to. It's just that users will be able to delete it even if it's still in the scene graph, which means probably on the next frame your program will crash...

And another point : what if an update callback is still running when the object 
is dereferenced? Will it be dereferenced too?...

You need to be careful not to invalidate iterators and not to delete an object from within its own callback. In general you will want to gather nodes in visitors / traversals, put them in a list and then remove them from the scene graph separately once the traversal has ended.

Other than that, could you give us the full code of a small test program to see why it's leaking, or even if it's really leaking? What do you use to see if it's leaking? Some tools have trouble understanding ref_ptrs and will report leaks where there are none...

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay    jean-sebastien.g...@cm-labs.com
                               http://www.cm-labs.com/
                        http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to