Hi Robert,

I've seen this problem in this situation :

- a class derived from osg::Group who override the "childInserted"
- in the "childInserted" : get the newly inserted child using "getChild"

But, to ensure that new childs are always inserted at the end of the group 
(which is what I needs in this particular situtation), I insert them using :

pGroup->insertChild(pNewChild, -1)

So the child is always added at the end, but the index passed in 
"childInserted" method was invalid.



> passing a index more than one beyond the end of current children size 
> suggests that something is amiss


Not sure about that, when I manage vector or list of objects, I always apply 
the following rule in the "insert" metod (and that's usefull !)

- if index < size => insert as usual
- if index > size => insert at the end

and, if index is "int" and not "unsigned int" :

- if index < 0 => insert at the end

So :

- to prepend : insert(0, something)
- to append : insert(-1, something)
- to insert : insert(index, something)

But usually, when I do that, the "insert" method returns the "real inserted 
index" : 

- return value < 0 => invalid/error/some problem
- return value = index => object was inserted where asked to
- return value != index => object was inserted at the end


Cheers,
Aurelien

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





_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to