From e399e10607bdc40a7ade1d4df6b10116fded7daa Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 1 Feb 2017 03:06:59 +0100 Subject: [PATCH] Add missing lock in shareMaterial --- components/nifosg/nifloader.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 66575699f6..c758e87364 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -1643,10 +1643,12 @@ namespace NifOsg osg::Material* shareMaterial(osg::Material* mat) { typedef std::set, CompareMaterial> MatCache; - static MatCache mats; - MatCache::iterator found = mats.find(mat); - if (found == mats.end()) - found = mats.insert(mat).first; + static MatCache sMats; + static OpenThreads::Mutex sMutex; + OpenThreads::ScopedLock lock(sMutex); + MatCache::iterator found = sMats.find(mat); + if (found == sMats.end()) + found = sMats.insert(mat).first; return *found; }