From b03a77284601a1fc01745372209a04c698193c2e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 19 Jul 2006 13:02:35 +0000 Subject: [PATCH] Added mutexes to RealizeCallbaks --- examples/osgcatch/osgcatch.cpp | 11 ++++++++--- examples/osgtexture3D/osgtexture3D.cpp | 26 +++++++++++++++++--------- 2 files changed, 25 insertions(+), 12 deletions(-) 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; };