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:
@@ -50,6 +50,8 @@
|
|||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
#include <simgear/misc/sgstream.hxx>
|
#include <simgear/misc/sgstream.hxx>
|
||||||
|
#include <simgear/threads/SGGuard.hxx>
|
||||||
|
|
||||||
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
|
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
|
||||||
#include <simgear/props/props_io.hxx>
|
#include <simgear/props/props_io.hxx>
|
||||||
#include <simgear/props/vectorPropTemplates.hxx>
|
#include <simgear/props/vectorPropTemplates.hxx>
|
||||||
@@ -455,6 +457,7 @@ Effect* SGMaterial::get_effect(int i)
|
|||||||
|
|
||||||
Effect* SGMaterial::get_effect(const SGTexturedTriangleBin& triangleBin)
|
Effect* SGMaterial::get_effect(const SGTexturedTriangleBin& triangleBin)
|
||||||
{
|
{
|
||||||
|
SGGuard<SGMutex> g(_lock);
|
||||||
if (_status.empty()) {
|
if (_status.empty()) {
|
||||||
SG_LOG( SG_GENERAL, SG_WARN, "No effect available.");
|
SG_LOG( SG_GENERAL, SG_WARN, "No effect available.");
|
||||||
return 0;
|
return 0;
|
||||||
@@ -466,6 +469,7 @@ Effect* SGMaterial::get_effect(const SGTexturedTriangleBin& triangleBin)
|
|||||||
|
|
||||||
Effect* SGMaterial::get_effect()
|
Effect* SGMaterial::get_effect()
|
||||||
{
|
{
|
||||||
|
SGGuard<SGMutex> g(_lock);
|
||||||
return get_effect(0);
|
return get_effect(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ class StateSet;
|
|||||||
}
|
}
|
||||||
|
|
||||||
#include <simgear/structure/SGSharedPtr.hxx>
|
#include <simgear/structure/SGSharedPtr.hxx>
|
||||||
|
#include <simgear/threads/SGThread.hxx> // for SGMutex
|
||||||
#include <simgear/math/SGMath.hxx>
|
#include <simgear/math/SGMath.hxx>
|
||||||
#include <simgear/bvh/BVHMaterial.hxx>
|
#include <simgear/bvh/BVHMaterial.hxx>
|
||||||
|
|
||||||
@@ -473,6 +474,9 @@ private:
|
|||||||
// Parameters from the materials file
|
// Parameters from the materials file
|
||||||
const SGPropertyNode* parameters;
|
const SGPropertyNode* parameters;
|
||||||
|
|
||||||
|
// per-material lock for entrypoints called from multiple threads
|
||||||
|
SGMutex _lock;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Internal constructors and methods.
|
// Internal constructors and methods.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user