[osg-users] how safe is to add nodes in cull traversal
Trajce Nikolov NICK
trajce.nikolov.nick at gmail.com
Sat Sep 10 21:15:43 PDT 2016
Hi again Robert,
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.
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.
Any other clue, hints, suggestions for such a un-trivial case?
Thanks a bunch again and again, I am asking for ignorance of this email if
it is too much off-regular topics
cheers,
Nick
On Sat, Sep 10, 2016 at 7:12 PM, Trajce Nikolov NICK <
trajce.nikolov.nick at gmail.com> wrote:
> Hi Robert
>
> > How long have you been using the OSG now?
>
> 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:
>
> - for every frame I have dynaimic list of objects (lights, with rtt
> cameras attached)
> - In custom cull visitor I am getting a new list of sorted cameras (this
> must happen in the cull traversal for reasons)
> - 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)
>
> 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
>
> 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
>
> Cheers,
> Nick
>
> On Sat, Sep 10, 2016 at 6:49 PM, Robert Osfield <robert.osfield at gmail.com>
> wrote:
>
>> On 10 September 2016 at 12:42, Trajce Nikolov NICK
>> <trajce.nikolov.nick at gmail.com> wrote:
>> > Hi Community,
>> >
>> > me again :-) .. As the subject says, I an having the viewer setup with
>> > CullDrawThreadPerContext and I want to add nodes in the cull traversal.
>> Is
>> > it safe to do so?
>>
>> How long have you been using the OSG now?
>>
>> Short answer. NO. Longer answer, NO it's not safe.
>>
>> Full answer: It's *not* generally safe to add nodes during any
>> traversal, especially the cull traversal. There are very specific
>> circumstances when it can be done during during a traversal but you
>> have to be fully aware of what can go wrong and make sure you don't
>> fall foul of any of the potential problems.
>>
>> A major gotcha with changing the scene graph in the cull traversal is
>> that multiple camera's can have multiple threads running cull
>> traversals on them on parallel. If you wanted to go change the scene
>> graph when threading is happened then you'd need to lock the node in
>> some way to prevent problems happening. There are lots of threading
>> pitfalls here - both for performance and obscure threading crashes.
>>
>> Another major issue is invalidation of iterators. If you have code
>> that traverses through a vector of children and as you handle one of
>> the children you decide it's time to add/remove/insert and new child
>> into the list being iterated then any reallocation of the vector being
>> iterator will invalidate the iterators. Invalidate the iterators and
>> bang you're app will go down in flames.
>>
>> So.... in almost all instances trying to add/remove/insert nodes
>> during the cull traversal is REALLY BAD IDEA.
>>
>> If you really want to do it. Go do it, you have the source code, you
>> have debuggers, you can go shoot yourself in the foot or if your lucky
>> work out a really narrow and safe way to do what you want to do. I
>> won't nurse you along in this route though. Strong recommendation,
>> don't play silly buggers, don't try it. It'll save you lots of time.
>>
>> Far better is do what other multi-threaded parts of the OSG do, do
>> what the DatabasePager does, load data in a background thread,
>> incremental compile new objects, when compilation is complete merge
>> the subgraph with the main scene graph as an update operation prior to
>> the update and event traversals. This approach is safe, scales
>> well, is well established to work well for multi-threaded and
>> applications that need to target a solid 60hz.
>>
>> Robert.
>> _______________________________________________
>> osg-users mailing list
>> osg-users at lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>
>
>
> --
> trajce nikolov nick
>
--
trajce nikolov nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160911/ade0d9f2/attachment-0002.htm>
More information about the osg-users
mailing list