diff --git a/planning/behavior_velocity_planner/src/scene_module/crosswalk/scene_crosswalk.cpp b/planning/behavior_velocity_planner/src/scene_module/crosswalk/scene_crosswalk.cpp index 58a8f8ef0fb23..7b034374cfd12 100644 --- a/planning/behavior_velocity_planner/src/scene_module/crosswalk/scene_crosswalk.cpp +++ b/planning/behavior_velocity_planner/src/scene_module/crosswalk/scene_crosswalk.cpp @@ -731,16 +731,18 @@ void CrosswalkModule::clampAttentionRangeByNeighborCrosswalks( boost::optional prev_crosswalk{boost::none}; boost::optional next_crosswalk{boost::none}; - for (size_t i = 0; i < crosswalks.size() - 1; ++i) { - const auto ll_front = crosswalks.at(i); - const auto ll_back = crosswalks.at(i + 1); + if (!crosswalks.empty()) { + for (size_t i = 0; i < crosswalks.size() - 1; ++i) { + const auto ll_front = crosswalks.at(i); + const auto ll_back = crosswalks.at(i + 1); - if (ll_front.id() == module_id_ && ll_back.id() != module_id_) { - next_crosswalk = ll_back; - } + if (ll_front.id() == module_id_ && ll_back.id() != module_id_) { + next_crosswalk = ll_back; + } - if (ll_front.id() != module_id_ && ll_back.id() == module_id_) { - prev_crosswalk = ll_front; + if (ll_front.id() != module_id_ && ll_back.id() == module_id_) { + prev_crosswalk = ll_front; + } } }