Skip to content

Commit

Permalink
Cleanup activeSensor structure to avoid segfaults
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-della-vedova committed Apr 3, 2020
1 parent 1f28607 commit 7750a41
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/systems/sensors/Sensors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,24 @@ void Sensors::RemoveSensor(const Entity &_entity)
auto idIter = this->dataPtr->entityToIdMap.find(_entity);
if (idIter != this->dataPtr->entityToIdMap.end())
{
// Remove from active sensors as well
// Locking mutex to make sure the vector is not being changed while
// the rendering thread is iterating over it
{
std::unique_lock<std::mutex> lock(this->dataPtr->sensorMaskMutex);
sensors::Sensor *s = this->dataPtr->sensorManager.Sensor(idIter->second);
auto rs = dynamic_cast<sensors::RenderingSensor *>(s);
auto activeSensorIt = std::find(this->dataPtr->activeSensors.begin(),
this->dataPtr->activeSensors.end(), rs);
if (activeSensorIt != this->dataPtr->activeSensors.end())
{
this->dataPtr->activeSensors.erase(activeSensorIt);
}
}
this->dataPtr->sensorIds.erase(idIter->second);
this->dataPtr->sensorManager.Remove(idIter->second);
this->dataPtr->entityToIdMap.erase(idIter);

}
}

Expand Down

0 comments on commit 7750a41

Please sign in to comment.