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
This commit is contained in:
parent
78a01ce2a5
commit
120bf699b2
@ -15,6 +15,7 @@
|
|||||||
#ifndef OSGDB_OBJECTWRAPPER
|
#ifndef OSGDB_OBJECTWRAPPER
|
||||||
#define OSGDB_OBJECTWRAPPER
|
#define OSGDB_OBJECTWRAPPER
|
||||||
|
|
||||||
|
#include <OpenThreads/ReentrantMutex>
|
||||||
#include <osgDB/Serializer>
|
#include <osgDB/Serializer>
|
||||||
#include <osg/ScriptEngine>
|
#include <osg/ScriptEngine>
|
||||||
|
|
||||||
@ -169,6 +170,8 @@ protected:
|
|||||||
ObjectWrapperManager();
|
ObjectWrapperManager();
|
||||||
virtual ~ObjectWrapperManager();
|
virtual ~ObjectWrapperManager();
|
||||||
|
|
||||||
|
OpenThreads::ReentrantMutex _wrapperMutex;
|
||||||
|
|
||||||
WrapperMap _wrappers;
|
WrapperMap _wrappers;
|
||||||
CompressorMap _compressors;
|
CompressorMap _compressors;
|
||||||
|
|
||||||
|
@ -647,6 +647,8 @@ void ObjectWrapperManager::addWrapper( ObjectWrapper* wrapper )
|
|||||||
{
|
{
|
||||||
if ( !wrapper ) return;
|
if ( !wrapper ) return;
|
||||||
|
|
||||||
|
OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_wrapperMutex);
|
||||||
|
|
||||||
WrapperMap::iterator itr = _wrappers.find( wrapper->getName() );
|
WrapperMap::iterator itr = _wrappers.find( wrapper->getName() );
|
||||||
if ( itr!=_wrappers.end() )
|
if ( itr!=_wrappers.end() )
|
||||||
{
|
{
|
||||||
@ -660,12 +662,16 @@ void ObjectWrapperManager::removeWrapper( ObjectWrapper* wrapper )
|
|||||||
{
|
{
|
||||||
if ( !wrapper ) return;
|
if ( !wrapper ) return;
|
||||||
|
|
||||||
|
OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_wrapperMutex);
|
||||||
|
|
||||||
WrapperMap::iterator itr = _wrappers.find( wrapper->getName() );
|
WrapperMap::iterator itr = _wrappers.find( wrapper->getName() );
|
||||||
if ( itr!=_wrappers.end() ) _wrappers.erase( itr );
|
if ( itr!=_wrappers.end() ) _wrappers.erase( itr );
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectWrapper* ObjectWrapperManager::findWrapper( const std::string& name )
|
ObjectWrapper* ObjectWrapperManager::findWrapper( const std::string& name )
|
||||||
{
|
{
|
||||||
|
OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_wrapperMutex);
|
||||||
|
|
||||||
WrapperMap::iterator itr = _wrappers.find( name );
|
WrapperMap::iterator itr = _wrappers.find( name );
|
||||||
if ( itr!=_wrappers.end() ) return itr->second.get();
|
if ( itr!=_wrappers.end() ) return itr->second.get();
|
||||||
|
|
||||||
@ -694,6 +700,8 @@ void ObjectWrapperManager::addCompressor( BaseCompressor* compressor )
|
|||||||
{
|
{
|
||||||
if ( !compressor ) return;
|
if ( !compressor ) return;
|
||||||
|
|
||||||
|
OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_wrapperMutex);
|
||||||
|
|
||||||
CompressorMap::iterator itr = _compressors.find( compressor->getName() );
|
CompressorMap::iterator itr = _compressors.find( compressor->getName() );
|
||||||
if ( itr!=_compressors.end() )
|
if ( itr!=_compressors.end() )
|
||||||
{
|
{
|
||||||
@ -707,12 +715,16 @@ void ObjectWrapperManager::removeCompressor( BaseCompressor* compressor )
|
|||||||
{
|
{
|
||||||
if ( !compressor ) return;
|
if ( !compressor ) return;
|
||||||
|
|
||||||
|
OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_wrapperMutex);
|
||||||
|
|
||||||
CompressorMap::iterator itr = _compressors.find( compressor->getName() );
|
CompressorMap::iterator itr = _compressors.find( compressor->getName() );
|
||||||
if ( itr!=_compressors.end() ) _compressors.erase( itr );
|
if ( itr!=_compressors.end() ) _compressors.erase( itr );
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseCompressor* ObjectWrapperManager::findCompressor( const std::string& name )
|
BaseCompressor* ObjectWrapperManager::findCompressor( const std::string& name )
|
||||||
{
|
{
|
||||||
|
OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_wrapperMutex);
|
||||||
|
|
||||||
CompressorMap::iterator itr = _compressors.find( name );
|
CompressorMap::iterator itr = _compressors.find( name );
|
||||||
if ( itr!=_compressors.end() ) return itr->second.get();
|
if ( itr!=_compressors.end() ) return itr->second.get();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user