Re: [osg-users] manual delete object

2009-06-02 Thread Rabbi Robinson
Hi,

Thanks, your hint already gave it all out. I was wondering if user need to keep 
track of the reference to Node assigned to Group. As you said, group use smart 
pointer internally so group-addChild(new Node) will delete the node created 
once group is gone.

Thank you!

Cheers,
Rabbi

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





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


[osg-users] manual delete object

2009-06-01 Thread Rabbi Robinson
Hi,

When I tried

Node* node = new Node;
delete node;

there is a compiler error saying destructor protected. How can I delete node 
that I am sure I no longer use.

Thank you!

Cheers,
Rabbi

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





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


Re: [osg-users] manual delete object

2009-06-01 Thread Tomlinson, Gordon
 
Nodes are derived from Object which is refcounted thus the destructor is
not directly accessible

You can use 

node-unref();
Node = NULL;

Gordon
Product Manager 3d
__
Gordon Tomlinson
Email  : gtomlinson @ overwatch.textron.com
__


-Original Message-
From: osg-users-boun...@lists.openscenegraph.org
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Rabbi
Robinson
Sent: Monday, June 01, 2009 10:55 AM
To: osg-users@lists.openscenegraph.org
Subject: [osg-users] manual delete object

Hi,

When I tried

Node* node = new Node;
delete node;

there is a compiler error saying destructor protected. How can I delete
node that I am sure I no longer use.

Thank you!

Cheers,
Rabbi

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





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


Re: [osg-users] manual delete object

2009-06-01 Thread Robert Osfield
Hi Rabbi,

The destructor of most OSG class is deliberately made protected so
your can't delete it directly using delete, it also prevents the class
from being created on the stack.

Why?  This is a C++ programming trick that can help prevent misue of
C++ classes that are reference counted, and the OSG uses reference
almost everywhere for it's memory management of scene graph classes so
it's crucial that users use reference counting rather than try and mix
and match objects memory management.

The final answer to your question, how do you delete... well you don't
you leave it up to smart pointers and reference counting to do the
job.  You simple do:

  {
  osg::ref_ptrNode node = new Node; // create node on stack and
take a reference to it.
  } // ref_ptr goes out of scope and decrements the reference count,
and if it goes to 0, then it's deleted.

Robert.

On Mon, Jun 1, 2009 at 3:54 PM, Rabbi Robinson longa...@gmail.com wrote:
 Hi,

 When I tried

 Node* node = new Node;
 delete node;

 there is a compiler error saying destructor protected. How can I delete node 
 that I am sure I no longer use.

 Thank you!

 Cheers,
 Rabbi

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





 ___
 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


Re: [osg-users] manual delete object

2009-06-01 Thread Rabbi Robinson
Hi,
Thanks, if later I reference the node from a group, will the reference count be 
increased for the node?

{
osg::ref_ptrNode node = new Node;
osg::ref_ptrGroup group = new Group;
group-addChild(node);
}

The reference count of node should be one outside the scope. Is it right that 
somehow group-addChild(node) increases the reference count of node?


Thank you!

Cheers,
Rabbi

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





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


Re: [osg-users] manual delete object

2009-06-01 Thread Robert Osfield
On Mon, Jun 1, 2009 at 4:39 PM, Rabbi Robinson longa...@gmail.com wrote:
 Hi,
 Thanks, if later I reference the node from a group, will the reference count 
 be increased for the node?

 {
 osg::ref_ptrNode node = new Node;
 osg::ref_ptrGroup group = new Group;
 group-addChild(node);
 }

 The reference count of node should be one outside the scope. Is it right that 
 somehow group-addChild(node) increases the reference count of node?

I won't answer this directly - an exercise for the reader...

The hint I'll give is that Group uses osg::ref_ptrosg::Node
internally so when you add a node it
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org