From a33e2462e92e6dd0e6c0dc0cc3385dc342b12f31 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Mon, 26 Aug 2024 16:42:47 -0700 Subject: [PATCH] Check ranges before access (#2540) Added a check for non-empty laser scan ranges before accessing the elements. Signed-off-by: Ian Chen --- src/systems/elevator/Elevator.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/systems/elevator/Elevator.cc b/src/systems/elevator/Elevator.cc index 53c172dcef..12fd5287f4 100644 --- a/src/systems/elevator/Elevator.cc +++ b/src/systems/elevator/Elevator.cc @@ -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 lock(this->mutex);