Hi Joel,

The code that you suggest is erroneous looks fine, while your code
with release() looks dubious.  The ref_ptr<>::release() decrements the
reference count without deleting the object, it's a special case that
should only be used when passing back a C pointer from a function that
creates the object, locally ref_ptr<> it but wishes to pass back a
plain C pointer.

For some reason I can determine you seem to be having far more
problems with than users normally have.  I don't have your full code
or and understanding of exactly what is going on with you
understanding of how things are meant to work to know what you are
missing.  The problems you are seeing are almost certainly down to how
you are doing things.  The best I can do is suggest you go back and
read the documentation on ref_ptr<> & tutorials.

Robert.

On Fri, Sep 23, 2011 at 12:16 PM, Joel Graff <[email protected]> wrote:
> Robert,
>
> This turns out to be more complicated than I anticipated.  You were right - 
> at least partly..  I think.  I did some research on ref_ptr's (consulted OSG 
> 3.0 Beginner's Guide and a few (conflicting) online tutorials) a few days 
> ago.  Fixed a few consistency issues, but didn't catch this problem...
>
> Anyway, part of the problem appears to lie in the fact that I had several 
> osg::ref_ptr var members to my Scene class which pointed to nodes in the 
> scene graph.
>
> My erroneous code:
>
>
> Code:
>
> _activeNode=NULL;
> _SceneRoot=NULL;
> _projectNode=NULL;
> _projectRoot=NULL;
>
> _root->removeChild( 0U );
> _root->addChild( model );
>
>
>
>
> The (apparently) correct code:
>
>
> Code:
>
> _root->removeChild( _projectRoot );
>
> _activeNode.release();
> _SceneRoot.release();
> _projectNode.release();
> _projectRoot.release();
>
> _root->addChild( model );
>
>
>
>
> What leaves me scratching my head a bit is the fact that I should have had to 
> release the pointers at all - these are, after all, smart pointers, and I 
> reassign them in the following lines to newly-added nodes.
>
> Anyway, the error actually appears to have been two-fold: 1. Assigning NULL 
> to my pointers and 2. calling removeChild (0U) rather than passing in the 
> node to remove.  In the latter error, I opted for specifying the index 
> assuming that since there's only one child to _root, it would have the first 
> position...
>
> The other odd thing I noticed is sometimes, on return from this call, my 
> Scene pointer wouldn't always be destroyed...  Referencing this post:
>
> http://forum.openscenegraph.org/viewtopic.php?t=8997&highlight=
>
> could it be this is conflicting with the draw thread?  At present, the 
> solution above appears to work consistently (and the erroneous code failed to 
> work consistently), but I'm nevertheless a bit worried...  (edit:) Now that I 
> think of it, maybe explicitly releasing the pointers is sparing me the 
> problem described in the above thread?
>
> Finally, I seem to have encountered a problem with the viewer using this 
> methodology.  That is, while my viewer's scene data is set to _root (which is 
> never destroyed), after loading a saved file, I get a debug error that tells 
> me "vector iterator is not incrementable".  Obviously related to the 
> removeChild() / addChild() calls...
>
> Thanks!
>
> Joel
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=42966#42966
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to