diff --git a/examples/osgcatch/osgcatch.cpp b/examples/osgcatch/osgcatch.cpp index 2789837b5..e91c041ea 100644 --- a/examples/osgcatch/osgcatch.cpp +++ b/examples/osgcatch/osgcatch.cpp @@ -1359,14 +1359,19 @@ class CompileStateCallback : public osgProducer::OsgCameraGroup::RealizeCallback { // now safe to construct sh.init(); - - if (_gameEventHandler) + { - _gameEventHandler->compileGLObjects(*(sh.getSceneView()->getState())); + OpenThreads::ScopedLock lock(_mutex); + + if (_gameEventHandler) + { + _gameEventHandler->compileGLObjects(*(sh.getSceneView()->getState())); + } } } + OpenThreads::Mutex _mutex; GameEventHandler* _gameEventHandler; }; diff --git a/examples/osgtexture3D/osgtexture3D.cpp b/examples/osgtexture3D/osgtexture3D.cpp index d4cf8d35a..5200d4476 100644 --- a/examples/osgtexture3D/osgtexture3D.cpp +++ b/examples/osgtexture3D/osgtexture3D.cpp @@ -101,23 +101,31 @@ class ConstructStateCallback : public osgProducer::OsgCameraGroup::RealizeCallba } virtual void operator()( osgProducer::OsgCameraGroup&, osgProducer::OsgSceneHandler& sh, const Producer::RenderSurface& ) - { - if (!_initialized) + { { - // only initialize state once, only need for cases where multiple graphics contexts are - // if which case this callback can get called multiple times. - _initialized = true; + OpenThreads::ScopedLock lock(_mutex); - if (_node) _node->setStateSet(constructState()); - } + if (!_initialized) + { + + // only initialize state once, only need for cases where multiple graphics contexts are + // if which case this callback can get called multiple times. + _initialized = true; + + if (_node) _node->setStateSet(constructState()); + } + + } + // now safe to con sh.init(); } - osg::Node* _node; - bool _initialized; + OpenThreads::Mutex _mutex; + osg::Node* _node; + bool _initialized; };