Race-condition fix in get_effect.

Adapted from a fix by Jeff Biggs. (Shows up easier when using osgEarth,
and multiple osgDB pager threads)
This commit is contained in:
James Turner
2014-02-10 17:59:02 +00:00
parent 781682f4ee
commit eef73953cb
2 changed files with 8 additions and 0 deletions

View File

@@ -50,6 +50,8 @@
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/sgstream.hxx>
#include <simgear/threads/SGGuard.hxx>
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
#include <simgear/props/props_io.hxx>
#include <simgear/props/vectorPropTemplates.hxx>
@@ -455,6 +457,7 @@ Effect* SGMaterial::get_effect(int i)
Effect* SGMaterial::get_effect(const SGTexturedTriangleBin& triangleBin)
{
SGGuard<SGMutex> g(_lock);
if (_status.empty()) {
SG_LOG( SG_GENERAL, SG_WARN, "No effect available.");
return 0;
@@ -466,6 +469,7 @@ Effect* SGMaterial::get_effect(const SGTexturedTriangleBin& triangleBin)
Effect* SGMaterial::get_effect()
{
SGGuard<SGMutex> g(_lock);
return get_effect(0);
}

View File

@@ -43,6 +43,7 @@ class StateSet;
}
#include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/threads/SGThread.hxx> // for SGMutex
#include <simgear/math/SGMath.hxx>
#include <simgear/bvh/BVHMaterial.hxx>
@@ -473,6 +474,9 @@ private:
// Parameters from the materials file
const SGPropertyNode* parameters;
// per-material lock for entrypoints called from multiple threads
SGMutex _lock;
////////////////////////////////////////////////////////////////////
// Internal constructors and methods.
////////////////////////////////////////////////////////////////////