From 52861ecbb04bea67341fdebcdf0bb9c7e6f9e22a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 14 Aug 2012 20:15:00 +0000 Subject: [PATCH] Added a mutex to protect the removal and addition of Uniform and Program to StateSet to avoid parents being invalidated when multi-threading. --- include/osgShadow/ViewDependentShadowMap | 1 + src/osgShadow/ViewDependentShadowMap.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/osgShadow/ViewDependentShadowMap b/include/osgShadow/ViewDependentShadowMap index a9f5e717a..70655cd22 100644 --- a/include/osgShadow/ViewDependentShadowMap +++ b/include/osgShadow/ViewDependentShadowMap @@ -187,6 +187,7 @@ protected: osg::ref_ptr _fallbackShadowMapTexture; typedef std::vector< osg::ref_ptr > Uniforms; + mutable OpenThreads::Mutex _accessUnfiromsAndProgramMutex; Uniforms _uniforms; osg::ref_ptr _program; }; diff --git a/src/osgShadow/ViewDependentShadowMap.cpp b/src/osgShadow/ViewDependentShadowMap.cpp index 6f587f9e5..889923e9f 100644 --- a/src/osgShadow/ViewDependentShadowMap.cpp +++ b/src/osgShadow/ViewDependentShadowMap.cpp @@ -1161,6 +1161,8 @@ void ViewDependentShadowMap::createShaders() unsigned int _baseTextureUnit = 0; + OpenThreads::ScopedLock lock(_accessUnfiromsAndProgramMutex); + _shadowCastingStateSet = new osg::StateSet; ShadowSettings* settings = getShadowedScene()->getShadowSettings(); @@ -2342,6 +2344,8 @@ osg::StateSet* ViewDependentShadowMap::selectStateSetForRenderingShadow(ViewDepe osg::ref_ptr stateset = vdd.getStateSet(); + OpenThreads::ScopedLock lock(_accessUnfiromsAndProgramMutex); + vdd.getStateSet()->clear(); vdd.getStateSet()->setTextureAttributeAndModes(0, _fallbackBaseTexture.get(), osg::StateAttribute::ON);