[osg-users] setLightingMode crash in multithread mode
Hi, First, my program work without any problem when the threading model is configure to single thread and i use one master camera and tree slaves cameras on a multiprocessor computer. When i call the method Viewer::setLightingMode of my viewer, osg crash when the method osgViewer::Renderer::cull is call by the threading engine. The crash occur in the following method sequence: ... osg100-osgd.dll!osg::StateSet::setModeToInherit osg100-osgd.dll!osg::StateSet::removeMode osg100-osgUtild.dll!osgUtil::SceneView::setLightingMode osg100-osgUtild.dll!osgUtil::SceneView::inheritCullSettings osg100-osgUtild.dll!osgUtil::SceneView::inheritCullSettings osg100-osgViewerd.dll!osgViewer::Renderer::cull osg100-osgViewerd.dll!osgViewer::Renderer::operator() osg100-osgd.dll!osg::OperationThread::run()ot13-openThreadsd.dll!OpenThreads::ThreadPrivateActions::StartThread Note that i have more then one thread that call the removeMode method in the same time when the error occure. I set the viewer data variance to DYNAMIC but when i debug the program, the SceneView data variance is still unspecified. I also set the data variance of each camera to DYNAMIC. Does i have to set the data variance of something else to DYNAMIC? Thank you! Cheers, Sylvain -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=57398#57398 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] setLightingMode crash in multithread mode
Hi Sylvain, The threading support in osgViewer doesn't include modifying the viewer and scene graph at the same time as cull. You should modify scene graph objects during update, or event traversals - basically any time outside of when viewer::renderingTraversals() are running. Robert. On 22 November 2013 14:08, Sylvain Comtois wrote: > Hi, > > First, my program work without any problem when the threading model is > configure to single thread and i use one master camera and tree slaves > cameras on a multiprocessor computer. > >When i call the method Viewer::setLightingMode of my viewer, osg crash > when the method osgViewer::Renderer::cull is call by the threading engine. > > The crash occur in the following method sequence: > > ... > osg100-osgd.dll!osg::StateSet::setModeToInherit > osg100-osgd.dll!osg::StateSet::removeMode > osg100-osgUtild.dll!osgUtil::SceneView::setLightingMode > osg100-osgUtild.dll!osgUtil::SceneView::inheritCullSettings > osg100-osgUtild.dll!osgUtil::SceneView::inheritCullSettings > osg100-osgViewerd.dll!osgViewer::Renderer::cull > osg100-osgViewerd.dll!osgViewer::Renderer::operator() > osg100-osgd.dll!osg::OperationThread::run()ot13-openThreadsd.dll!OpenThreads::ThreadPrivateActions::StartThread > >Note that i have more then one thread that call the removeMode method in > the same time when the error occure. > >I set the viewer data variance to DYNAMIC but when i debug the program, > the SceneView data variance is still unspecified. I also set the data > variance of each camera to DYNAMIC. > >Does i have to set the data variance of something else to DYNAMIC? > > Thank you! > > Cheers, > Sylvain > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=57398#57398 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] setLightingMode crash in multithread mode
Hi Robert, I use two way to modify my scene graph. The first one is using the UpdateCallback each time it is possible. The second one is when we are outside the ViewerBase::frame() function. Our application have a lot of threads and i use a mutex to be sure the OSG tree is never access in the same time by two or more threads. The code like this: mRenderingTreeMutex.lock mViewer->frame() mRenderingTreeMutex.Unlock And each time i touch the OSG tree, i use the same mutex. mRenderingTreeMutex.lock Modifiying OSG tree mRenderingTreeMutex.Unlock So in my case i call the Viewer::setLightingMode between my mRenderingTreeMutex and the function modify the internal variable _lightingMode. According to the debugger, this variable is process during the cull_draw that is made by all camera's thread in the same time. So, during one thread call the _globalStateSet->removeMode(GL_LIGHTING) function, another one use the _globalStateSet variable and this variable is the same for all threads that cause the crash. Everything append in the void SceneView::setLightingMode(LightingMode mode) function. To temporary solve my problem, i add a mutex to protect the access to the _globalStateSet variable. Maybe this variable can be process in the update instead of the cull/draw? Thank you! Cheers, Sylvain -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=59099#59099 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] setLightingMode crash in multithread mode
Hi Sylvain, n 22 April 2014 14:30, Sylvain Comtois wrote: > Hi Robert, > >I use two way to modify my scene graph. > >The first one is using the UpdateCallback each time it is possible. >The second one is when we are outside the ViewerBase::frame() function. >Our application have a lot of threads and i use a mutex to be sure the OSG > tree is never access in the same time by two or more threads. > > The code like this: > >mRenderingTreeMutex.lock >mViewer->frame() >mRenderingTreeMutex.Unlock > >And each time i touch the OSG tree, i use the same mutex. > >mRenderingTreeMutex.lock >Modifiying OSG tree >mRenderingTreeMutex.Unlock > >So in my case i call the Viewer::setLightingMode between my > mRenderingTreeMutex and the function modify the internal variable > _lightingMode. According to the debugger, this variable is process during the > cull_draw that is made by all camera's thread in the same time. > >So, during one thread call the _globalStateSet->removeMode(GL_LIGHTING) > function, another one use the _globalStateSet variable and this variable is > the same for all threads that cause the crash. > >Everything append in the void SceneView::setLightingMode(LightingMode > mode) function. > >To temporary solve my problem, i add a mutex to protect the access to the > _globalStateSet variable. > >Maybe this variable can be process in the update instead of the cull/draw? Thanks for the update. Looking through where SceneView::setLightingMode() gets called the one that looks suspicious is the SceneView::inheritCullSettings. The inheritCullSettings is meant to update the SceneView's local data to reflect settings that are inherited from above. What it shouldn't be doing is modifying external data - which in this case is the _globalStateSet as this is the data structured that is shared between the different viewer Cameras that are being threaded. SceneView's design is a bit of hang up of it's role in the early days of the OSG development, before the days of multi-threading. The particular bug you've uncovered is likely something that others users haven't come across simply because most users of multi-theaded OSG apps don't need to go change LightingMode like yours does. I haven't yet worked out the best solution, but my current inclination is to move the OpenGL lighting configuration in response to the View(er)::setLightingMode() to be moved out of SceneView and into View::setLightingMode(), the SceneView::inheritCullSettings would then ignore the local LightingMode settings. Or for use to move the setting of the Light/GLMode modes in SceneView from working on the global stateset to one of the local StateSet's that SceneView manages. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org