<div dir="ltr">Hi again Robert,<div><br></div><div>right at the beginning to apologize if this sounds 'odd' again, but I am really struggling. In my previous email I tried to explain the situation with this cull/update thing in the code I am hacking. What I am after is to have extra update of the scenegraph after the cull traversal. I was thinking to mimic the TileMapper approach from the txp loader (just to refresh, you have a traversal with the TileMapper to set up the smart mesh there in the root and this is hapenning in the Cull traversal, after this is happening you launch the normal cull visiting). This will not work for me since the TileMapper approach is not modifying the scenegraph, only setting the tile seams for matching the neighbouring tiles.</div><div><br></div><div>My recent idea is to have all of this 'delayed' by one frame: collect the results from the cull traversal and then modify the scene graph before the next frame. This might work with one frame delay. And I am about to start implementing it since I am out of other ideas.</div><div><br></div><div>Any other clue, hints, suggestions for such a un-trivial case?</div><div><br></div><div>Thanks a bunch again and again, I am asking for ignorance of this email if it is too much off-regular topics</div><div><br></div><div>cheers,</div><div>Nick</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Sep 10, 2016 at 7:12 PM, Trajce Nikolov NICK <span dir="ltr"><<a href="mailto:trajce.nikolov.nick@gmail.com" target="_blank">trajce.nikolov.nick@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Robert<span class=""><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></span><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"><div><div class="h5"><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><<a href="mailto:trajce.nikolov.nick@gmail.com" target="_blank">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" target="_blank">osg-users@lists.openscenegraph<wbr>.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.or<wbr>g/listinfo.cgi/osg-users-opens<wbr>cenegraph.org</a><br>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div data-smartmail="gmail_signature">trajce nikolov nick<br></div>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">trajce nikolov nick<br></div>
</div>