diff --git a/include/osg/Shader b/include/osg/Shader index 4347cf9a5..6b7ad0bca 100644 --- a/include/osg/Shader +++ b/include/osg/Shader @@ -306,6 +306,7 @@ class OSG_EXPORT Shader : public osg::Object /** osg::Programs that this osg::Shader is attached to */ typedef std::set< osg::Program* > ProgramSet; ProgramSet _programSet; + OpenThreads::Mutex _programSetMutex; mutable osg::buffered_value< osg::ref_ptr > _pcsList; private: diff --git a/src/osg/Shader.cpp b/src/osg/Shader.cpp index 2b8481e42..de9055707 100644 --- a/src/osg/Shader.cpp +++ b/src/osg/Shader.cpp @@ -483,6 +483,7 @@ Shader::PerContextShader* Shader::getPCS(osg::State& state) const bool Shader::addProgramRef( Program* program ) { + OpenThreads::ScopedLock lk(_programSetMutex); ProgramSet::iterator itr = _programSet.find(program); if( itr != _programSet.end() ) return false; @@ -492,6 +493,7 @@ bool Shader::addProgramRef( Program* program ) bool Shader::removeProgramRef( Program* program ) { + OpenThreads::ScopedLock lk(_programSetMutex); ProgramSet::iterator itr = _programSet.find(program); if( itr == _programSet.end() ) return false; @@ -507,6 +509,7 @@ void Shader::dirtyShader() if( _pcsList[cxt].valid() ) _pcsList[cxt]->requestCompile(); } + OpenThreads::ScopedLock lk(_programSetMutex); // Also mark Programs that depend on us as needing relink. for( ProgramSet::iterator itr = _programSet.begin(); itr != _programSet.end(); ++itr )