<div dir="ltr">Hi Robert<div><br></div><div>> <span style="font-size:12.8px">How long have you been using the OSG now?</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Since 2003? :-) .. I knew the answer but I was "hoping" to maybe see some light in dealing with sort of very complex code. Here is the situation in brief:</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">- for every frame I have dynaimic list of objects (lights, with rtt cameras attached)</span></div><div><span style="font-size:12.8px">- In custom cull visitor I am getting a new list of sorted cameras (this must happen in the cull traversal for reasons)</span></div><div><span style="font-size:12.8px">- now after the cull is done, I have to make the new list from the cull traversal 'active' for the frame (active means, disable/erase the old list and making the new one actual - and these is by updating the scenegraph)</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">But, while writing this I just recall what you did for the txp loader for the smart mesh handling with the TileMapper, where custom cull traversal is launched before the frame</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Please take my apologize for asking 'stupid' questions ;-), but sometime I struggle and the panic is faster then the rational thinking and the experience. I need it in written :-). Thanks again for the good description. Hope it will help others too</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Cheers,</span></div><div><span style="font-size:12.8px">Nick</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Sep 10, 2016 at 6:49 PM, Robert Osfield <span dir="ltr"><<a href="mailto:robert.osfield@gmail.com" target="_blank">robert.osfield@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 10 September 2016 at 12:42, Trajce Nikolov NICK<br>
<span class=""><<a href="mailto:trajce.nikolov.nick@gmail.com">trajce.nikolov.nick@gmail.com</a><wbr>> wrote:<br>
> Hi Community,<br>
><br>
> me again :-) .. As the subject says, I an having the viewer setup with<br>
> CullDrawThreadPerContext and I want to add nodes in the cull traversal. Is<br>
> it safe to do so?<br>
<br>
</span>How long have you been using the OSG now?<br>
<br>
Short answer. NO. Longer answer, NO it's not safe.<br>
<br>
Full answer: It's *not* generally safe to add nodes during any<br>
traversal, especially the cull traversal. There are very specific<br>
circumstances when it can be done during during a traversal but you<br>
have to be fully aware of what can go wrong and make sure you don't<br>
fall foul of any of the potential problems.<br>
<br>
A major gotcha with changing the scene graph in the cull traversal is<br>
that multiple camera's can have multiple threads running cull<br>
traversals on them on parallel. If you wanted to go change the scene<br>
graph when threading is happened then you'd need to lock the node in<br>
some way to prevent problems happening. There are lots of threading<br>
pitfalls here - both for performance and obscure threading crashes.<br>
<br>
Another major issue is invalidation of iterators. If you have code<br>
that traverses through a vector of children and as you handle one of<br>
the children you decide it's time to add/remove/insert and new child<br>
into the list being iterated then any reallocation of the vector being<br>
iterator will invalidate the iterators. Invalidate the iterators and<br>
bang you're app will go down in flames.<br>
<br>
So.... in almost all instances trying to add/remove/insert nodes<br>
during the cull traversal is REALLY BAD IDEA.<br>
<br>
If you really want to do it. Go do it, you have the source code, you<br>
have debuggers, you can go shoot yourself in the foot or if your lucky<br>
work out a really narrow and safe way to do what you want to do. I<br>
won't nurse you along in this route though. Strong recommendation,<br>
don't play silly buggers, don't try it. It'll save you lots of time.<br>
<br>
Far better is do what other multi-threaded parts of the OSG do, do<br>
what the DatabasePager does, load data in a background thread,<br>
incremental compile new objects, when compilation is complete merge<br>
the subgraph with the main scene graph as an update operation prior to<br>
the update and event traversals. This approach is safe, scales<br>
well, is well established to work well for multi-threaded and<br>
applications that need to target a solid 60hz.<br>
<br>
Robert.<br>
______________________________<wbr>_________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.<wbr>openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.<wbr>org/listinfo.cgi/osg-users-<wbr>openscenegraph.org</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">trajce nikolov nick<br></div>
</div>