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));