]> git.mxchange.org Git - simgear.git/commitdiff
Race-condition fix in get_effect.
authorJames Turner <zakalawe@mac.com>
Mon, 10 Feb 2014 17:59:02 +0000 (17:59 +0000)
committerJames Turner <zakalawe@mac.com>
Mon, 10 Feb 2014 17:59:02 +0000 (17:59 +0000)
Adapted from a fix by Jeff Biggs. (Shows up easier when using osgEarth,
and multiple osgDB pager threads)

simgear/scene/material/mat.cxx
simgear/scene/material/mat.hxx

index 46af662b05166a22def634adb0e7a6821684dc20..738dd5d028b01cb236664ee32468682e4c1a4fd7 100644 (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);
 }
 
index 7d03b5772dc610a40e90033dc0e187a9d9bcf7c0..7ed5958c962b17f7609ac572306cc45e96fe364c 100644 (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.
   ////////////////////////////////////////////////////////////////////