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);