Another thing I believe is often overlooked is using ref_ptr's with
objects who attempt to properly support copy construction. It's such a
hard thing to get right that I plan eventually adding a chapter about it
in the osgWidget docs, when the time comes.

It's not uncommon to want to keep ref_ptr's around to objects you add to
a scene in your own classes (OSG-derived or otherwise), but properly
setting that ref_ptr again in the new object after a call to clone() can
be tricky depending on what type of osg::CopyOp you use. Maybe a chapter
on this could one day go into the QSG, though it's more of a hybrid
topic between C++ and OSG itself.

On Wed, 2008-04-09 at 18:05 +0200, [EMAIL PROTECTED] wrote:
> I just started using OSG and have never used ref_ptr's before, though I've 
> read the "A Short Introduction to the Basic Principles of the Open Scene 
> Graph" and belive I understand the concept. But I wonder if you have any 
> advice on the use of ref_ptr's on OSG objects, and If you use them in some 
> standard way.
> 
> I recon all the objects that inherits from "Referenced" should use ref_ptr 
> for safer memory alloction/deleting, but I guess it's just a subjective 
> choice.
> 
> The tutorials though use "dumb" pointers as in the Basic Geometry example:
> "
> ...
> int main()
> {
>    ...
>    osg::Group* root = new osg::Group();
>    osg::Geode* pyramidGeode = new osg::Geode();
>    osg::Geometry* pyramidGeometry = new osg::Geometry();
> "
> 
> but i guess it's just for simplicity.
> 
> In the guide "A Short Introduction to the Basic Principles of the Open Scene 
> Graph" on the use of ref_ptr, they first create a node using ref pointer, 
> then they add a node using new, and say:
> 
> "
> Line 25 does more or less the same thing as the previous case. The
> difference is that the geode is allocated with new and added as group's
> child in a single line of code. This is quite safe, too, because there are
> not many bad things that can happen in between (after all, there is no
> in between.)
> "
> 
> that may be a little missleading since it's not a smart pointer, and needs to 
> be deleted explicitly.
> 
> Erlend
> 
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 

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

Reply via email to