From bf3ffb4225f959f92b2ec5cd01ed06cfb2d7a6f6 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Wed, 7 Apr 2021 03:03:40 -0300 Subject: [PATCH] Protect DepthCameraPlugin globals with a mutex (#2949) Signed-off-by: Ivan Santiago Paunovic --- plugins/DepthCameraPlugin.cc | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/plugins/DepthCameraPlugin.cc b/plugins/DepthCameraPlugin.cc index aa71dd8429..a42cec6dbb 100644 --- a/plugins/DepthCameraPlugin.cc +++ b/plugins/DepthCameraPlugin.cc @@ -16,16 +16,20 @@ */ #include +#include +#include #include "plugins/DepthCameraPlugin.hh" using namespace gazebo; GZ_REGISTER_SENSOR_PLUGIN(DepthCameraPlugin) +std::mutex global_maps_mutex; + // Added this map to avoid breaking the ABI -static std::map +static std::unordered_map connection_reflectance_map; -static std::map +static std::unordered_map connection_normals_map; ///////////////////////////////////////////////// DepthCameraPlugin::DepthCameraPlugin() @@ -40,13 +44,9 @@ DepthCameraPlugin::~DepthCameraPlugin() this->newRGBPointCloudConnection.reset(); this->newImageFrameConnection.reset(); - std::map::iterator it; - it = connection_reflectance_map.find(this); - it->second.reset(); - connection_reflectance_map.erase(it); - it = connection_normals_map.find(this); - it->second.reset(); - connection_normals_map.erase(it); + std::lock_guard guard{global_maps_mutex}; + connection_reflectance_map.erase(this); + connection_normals_map.erase(this); this->parentSensor.reset(); this->depthCamera.reset(); @@ -93,6 +93,7 @@ void DepthCameraPlugin::Load(sensors::SensorPtr _sensor, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5)); + std::lock_guard guard{global_maps_mutex}; connection_reflectance_map. insert(std::pair (this, newReflectanceFrameConnection));