diff --git a/simgear/scene/material/mat.cxx b/simgear/scene/material/mat.cxx index 46af662b..738dd5d0 100644 --- a/simgear/scene/material/mat.cxx +++ b/simgear/scene/material/mat.cxx @@ -50,6 +50,8 @@ #include #include #include +#include + #include #include #include @@ -455,6 +457,7 @@ Effect* SGMaterial::get_effect(int i) Effect* SGMaterial::get_effect(const SGTexturedTriangleBin& triangleBin) { + SGGuard 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 g(_lock); return get_effect(0); } diff --git a/simgear/scene/material/mat.hxx b/simgear/scene/material/mat.hxx index 7d03b577..7ed5958c 100644 --- a/simgear/scene/material/mat.hxx +++ b/simgear/scene/material/mat.hxx @@ -43,6 +43,7 @@ class StateSet; } #include +#include // for SGMutex #include #include @@ -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. ////////////////////////////////////////////////////////////////////