diff --git a/dartsim/src/GzOdeCollisionDetector.cc b/dartsim/src/GzOdeCollisionDetector.cc index 6a81b4e06..13e96e980 100644 --- a/dartsim/src/GzOdeCollisionDetector.cc +++ b/dartsim/src/GzOdeCollisionDetector.cc @@ -16,6 +16,7 @@ */ #include +#include #include #include @@ -43,6 +44,13 @@ GzOdeCollisionDetector::Registrar ///////////////////////////////////////////////// std::shared_ptr GzOdeCollisionDetector::create() { + // GzOdeCollisionDetector constructor calls the OdeCollisionDetector + // constructor, that calls the non-thread safe dInitODE2(0). + // To mitigate this problem, we use a static mutex to ensure that + // each GzOdeCollisionDetector constructor is called not at the same time. + // See https://github.com/gazebosim/gz-sim/issues/18 for more info. + static std::mutex odeInitMutex; + std::unique_lock lock(odeInitMutex); return std::shared_ptr(new GzOdeCollisionDetector()); }