diff --git a/simgear/scene/material/matlib.cxx b/simgear/scene/material/matlib.cxx index 2ff1624e..bbf58b32 100644 --- a/simgear/scene/material/matlib.cxx +++ b/simgear/scene/material/matlib.cxx @@ -83,6 +83,8 @@ bool SGMaterialLib::load( const SGPath &fg_root, const SGPath& mpath, options->setObjectCacheHint(osgDB::Options::CACHE_ALL); options->setDatabasePath(fg_root.utf8Str()); + std::lock_guard g(d->mutex); + simgear::PropertyList blocks = materialblocks.getChildren("region"); simgear::PropertyList::const_iterator block_iter = blocks.begin(); @@ -153,14 +155,20 @@ bool SGMaterialLib::load( const SGPath &fg_root, const SGPath& mpath, // find a material record by material name and tile center SGMaterial *SGMaterialLib::find( const string& material, const SGVec2f center ) const +{ + std::lock_guard g(d->mutex); + return internalFind(material, center); +} + +SGMaterial* SGMaterialLib::internalFind(const string& material, const SGVec2f center) const { SGMaterial *result = NULL; const_material_map_iterator it = matlib.find( material ); - if ( it != end() ) { + if (it != end()) { // We now have a list of materials that match this // name. Find the first one that matches. - // We start at the end of the list, as the materials - // list is ordered with the smallest regions at the end. + // We start at the end of the list, as the materials + // list is ordered with the smallest regions at the end. material_list::const_reverse_iterator iter = it->second.rbegin(); while (iter != it->second.rend()) { result = *iter; @@ -184,11 +192,12 @@ SGMaterial *SGMaterialLib::find( const string& material, const SGGeod& center ) SGMaterialCache *SGMaterialLib::generateMatCache(SGVec2f center) { SGMaterialCache* newCache = new SGMaterialCache(); + std::lock_guard g(d->mutex); + material_map::const_reverse_iterator it = matlib.rbegin(); for (; it != matlib.rend(); ++it) { - newCache->insert(it->first, find(it->first, center)); + newCache->insert(it->first, internalFind(it->first, center)); } - return newCache; } diff --git a/simgear/scene/material/matlib.hxx b/simgear/scene/material/matlib.hxx index ff80d795..d09c96d2 100644 --- a/simgear/scene/material/matlib.hxx +++ b/simgear/scene/material/matlib.hxx @@ -81,7 +81,10 @@ private: typedef material_map::const_iterator const_material_map_iterator; material_map matlib; - + + + SGMaterial* internalFind(const std::string& material, const SGVec2f center) const; + public: // Constructor