From eef73953cba8782da01503c6bb6d86e2d41d1851 Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 10 Feb 2014 17:59:02 +0000 Subject: [PATCH] Race-condition fix in get_effect. Adapted from a fix by Jeff Biggs. (Shows up easier when using osgEarth, and multiple osgDB pager threads) --- simgear/scene/material/mat.cxx | 4 ++++ simgear/scene/material/mat.hxx | 4 ++++ 2 files changed, 8 insertions(+) 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. //////////////////////////////////////////////////////////////////// -- 2.39.2