Re: [osg-users] Pointer ownership when reading a node file

2014-12-02 Thread Rico Widmer
Hi,

when I use osgDB::readNodeFile() for reading a file, the function returns a 
pointer to a node. The destructor of the Node class is protected and it says 
that it is deleted when not referenced any more.

So is it enough to store the returned Node* in a ref_ptr? Such a pointer 
is dereferenced automatically when going out of scope e.g. when the object is 
destroyed.

I use OSG 3.0.1.1

Thank you!

Cheers,
for

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=61895#61895





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Pointer ownership when reading a node file

2014-12-03 Thread Robert Osfield
Hi Rico,

On 28 November 2014 at 09:07, Rico Widmer  wrote:

> when I use osgDB::readNodeFile() for reading a file, the function returns
> a pointer to a node. The destructor of the Node class is protected and it
> says that it is deleted when not referenced any more.
>

The destructed is deliberately made protected to prevent your from directly
deleting it - this is done for almost all Objects in the OSG that should be
managed via reference counting.  The osg::ref_ptr<> is the safest way to
manage this reference counting.



> So is it enough to store the returned Node* in a ref_ptr? Such a
> pointer is dereferenced automatically when going out of scope e.g. when the
> object is destroyed.
>

Bingo, this is exactly what you are meant to do when managing most OSG
objects - in particular all the scene graph nodes/state attributes/geometry
etc.  There are times when you can temporarily use a C pointer rather than
a ref_ptr<> if you know that the object won't be deleted or leaked during
that code block.  In the case of being deleted on has to consider whether
the object might be deleted by another thread whilst you are using a C
pointer.   There are also readRefNodeFile() functions that are equivalents
of readNodeFile() for apps that know that the objects are being cached and
used by other threads.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Pointer ownership when reading a node file

2014-12-03 Thread Rico Widmer
Thank you very much for your help Robert.

Rico

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=61957#61957





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org