From 120bf699b2c2c8fb2542b2b0a56d93013e53f745 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 1 Jun 2015 12:07:04 +0000 Subject: [PATCH] From Frashud Lashkari, "I was getting "Unsupported wrapper class..." error messages when attempting to load osgb models simultaneously from multiple threads. I believe the problem is caused by un-synchronized access to the global osgDB::ObjectWrapperManager class. I've attached a change that adds a mutex to the class and uses it when accessing the internal wrapper/compress maps. This appears to fix the issues I was having." git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14880 16af8721-9629-0410-8352-f15c8da7e697 --- include/osgDB/ObjectWrapper | 3 +++ src/osgDB/ObjectWrapper.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/osgDB/ObjectWrapper b/include/osgDB/ObjectWrapper index 8003cb8a3..80424880f 100644 --- a/include/osgDB/ObjectWrapper +++ b/include/osgDB/ObjectWrapper @@ -15,6 +15,7 @@ #ifndef OSGDB_OBJECTWRAPPER #define OSGDB_OBJECTWRAPPER +#include #include #include @@ -169,6 +170,8 @@ protected: ObjectWrapperManager(); virtual ~ObjectWrapperManager(); + OpenThreads::ReentrantMutex _wrapperMutex; + WrapperMap _wrappers; CompressorMap _compressors; diff --git a/src/osgDB/ObjectWrapper.cpp b/src/osgDB/ObjectWrapper.cpp index 1b98cedb0..07f5e0a20 100644 --- a/src/osgDB/ObjectWrapper.cpp +++ b/src/osgDB/ObjectWrapper.cpp @@ -647,6 +647,8 @@ void ObjectWrapperManager::addWrapper( ObjectWrapper* wrapper ) { if ( !wrapper ) return; + OpenThreads::ScopedLock lock(_wrapperMutex); + WrapperMap::iterator itr = _wrappers.find( wrapper->getName() ); if ( itr!=_wrappers.end() ) { @@ -660,12 +662,16 @@ void ObjectWrapperManager::removeWrapper( ObjectWrapper* wrapper ) { if ( !wrapper ) return; + OpenThreads::ScopedLock lock(_wrapperMutex); + WrapperMap::iterator itr = _wrappers.find( wrapper->getName() ); if ( itr!=_wrappers.end() ) _wrappers.erase( itr ); } ObjectWrapper* ObjectWrapperManager::findWrapper( const std::string& name ) { + OpenThreads::ScopedLock lock(_wrapperMutex); + WrapperMap::iterator itr = _wrappers.find( name ); if ( itr!=_wrappers.end() ) return itr->second.get(); @@ -694,6 +700,8 @@ void ObjectWrapperManager::addCompressor( BaseCompressor* compressor ) { if ( !compressor ) return; + OpenThreads::ScopedLock lock(_wrapperMutex); + CompressorMap::iterator itr = _compressors.find( compressor->getName() ); if ( itr!=_compressors.end() ) { @@ -707,12 +715,16 @@ void ObjectWrapperManager::removeCompressor( BaseCompressor* compressor ) { if ( !compressor ) return; + OpenThreads::ScopedLock lock(_wrapperMutex); + CompressorMap::iterator itr = _compressors.find( compressor->getName() ); if ( itr!=_compressors.end() ) _compressors.erase( itr ); } BaseCompressor* ObjectWrapperManager::findCompressor( const std::string& name ) { + OpenThreads::ScopedLock lock(_wrapperMutex); + CompressorMap::iterator itr = _compressors.find( name ); if ( itr!=_compressors.end() ) return itr->second.get();