Skip to content

Commit

Permalink
Check ranges before access (#2540)
Browse files Browse the repository at this point in the history
Added a check for non-empty laser scan ranges before accessing the elements.

Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 authored Aug 26, 2024
1 parent bf05593 commit a33e246
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/systems/elevator/Elevator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ void ElevatorPrivate::UpdateState(const gz::sim::UpdateInfo &_info,
void ElevatorPrivate::OnLidarMsg(size_t _floorLevel,
const msgs::LaserScan &_msg)
{
if (_msg.ranges_size() <= 0)
return;

bool isDoorwayBlocked = _msg.ranges(0) < _msg.range_max() - 0.005;
if (isDoorwayBlocked == this->isDoorwayBlockedStates[_floorLevel]) return;
std::lock_guard<std::recursive_mutex> lock(this->mutex);
Expand Down

0 comments on commit a33e246

Please sign in to comment.