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