Hi Jannik,

I will need to think further about this issue, but as is the change
would invert the StateSet inheritance, so a slave's Camera's StateSet
would be above the master's Camera's StateSet.  Have a look at
SceneView.cpp's pushStateSet for the global and the secondary
StateSet's:

    if (_globalStateSet.valid())
cullVisitor->pushStateSet(_globalStateSet.get());
    if (_secondaryStateSet.valid())
cullVisitor->pushStateSet(_secondaryStateSet.get());
    if (_localStateSet.valid()) cullVisitor->pushStateSet(_localStateSet.get());

If the globalStateSet is shared, and being modified by multiple
threads then we'll either change the threads to avoid modifying the
globalStateSet or lock it's modification somehow.  Possibly we could
change SceneView::setLightingMode() and inhertiCullSettings to the
modify the secondaryStateSet or localStateSet.

We will need to be careful of any knock effects of this though.  I
haven't yet had time to reflect deeply on this.  My inclination is to
change SceneView so it doesn't modify the globalStateSet.

Robert.


On 5 June 2015 at 18:33, Jannik Heller <[email protected]> wrote:
> Hi Robert,
>
> I found a race condition in the OSG when using slave cameras and 
> CullThreadPerCamera threading model.
>
> In the Renderer constructor, we have:
>
>     osg::Camera* masterCamera = _camera->getView() ? 
> _camera->getView()->getCamera() : camera;
>
>     osg::StateSet* global_stateset = 0;
>     osg::StateSet* secondary_stateset = 0;
>     if (_camera != masterCamera)
>     {
>         global_stateset = masterCamera->getOrCreateStateSet();
>         secondary_stateset = _camera->getStateSet();
>     }
>     else
>     {
>         global_stateset = _camera->getOrCreateStateSet();
>     }
>
> meaning, the master camera and the slave camera get the same _globalStateSet 
> assigned.
>
> Later, in each Camera's culling thread, SceneView::inheritCullSettings will 
> call SceneView::setLightingMode, which modifies _globalStateSet without 
> locking. A crash ensues.
>
> I fixed the crash by changing the assignments to:
>
>     if (_camera != masterCamera)
>     {
>         secondary_stateset = masterCamera->getOrCreateStateSet();
>     }
>     global_stateset = _camera->getOrCreateStateSet();
>
> That makes more sense, the global_stateset is the one we can safely modify, 
> i.e. belonging to our Camera, and secondary_stateset is the one we just push 
> through to the CullVisitor without further changes.
>
> Thanks,
> Jannik
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=63961#63961
>
>
>
>
> _______________________________________________
> osg-submissions mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
>
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to