From 35fd9a0d4cf258aef28aa9dc6a472e950117e4d9 Mon Sep 17 00:00:00 2001 From: Shumpei Wakabayashi <42209144+shmpwk@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:50:13 +0900 Subject: [PATCH] fix(traffic_light_utils): prevent accessing nullopt (#9163) (#1621) Signed-off-by: satoshi-ota Co-authored-by: Satoshi OTA <44889564+satoshi-ota@users.noreply.github.com> --- .../src/utils/traffic_light_utils.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/planning/behavior_path_planner/autoware_behavior_path_planner_common/src/utils/traffic_light_utils.cpp b/planning/behavior_path_planner/autoware_behavior_path_planner_common/src/utils/traffic_light_utils.cpp index 39e5ae79edc33..42f6cd02ad361 100644 --- a/planning/behavior_path_planner/autoware_behavior_path_planner_common/src/utils/traffic_light_utils.cpp +++ b/planning/behavior_path_planner/autoware_behavior_path_planner_common/src/utils/traffic_light_utils.cpp @@ -34,11 +34,13 @@ double getDistanceToNextTrafficLight( lanelet::utils::to2D(lanelet_point).basicPoint()); for (const auto & element : current_lanelet.regulatoryElementsAs()) { - lanelet::ConstLineString3d lanelet_stop_lines = element->stopLine().value(); + const auto lanelet_stop_lines = element->stopLine(); + + if (!lanelet_stop_lines.has_value()) continue; const auto to_stop_line = lanelet::geometry::toArcCoordinates( lanelet::utils::to2D(current_lanelet.centerline()), - lanelet::utils::to2D(lanelet_stop_lines).front().basicPoint()); + lanelet::utils::to2D(lanelet_stop_lines.value()).front().basicPoint()); const auto distance_object_to_stop_line = to_stop_line.length - to_object.length; @@ -61,11 +63,13 @@ double getDistanceToNextTrafficLight( } for (const auto & element : llt.regulatoryElementsAs()) { - lanelet::ConstLineString3d lanelet_stop_lines = element->stopLine().value(); + const auto lanelet_stop_lines = element->stopLine(); + + if (!lanelet_stop_lines.has_value()) continue; const auto to_stop_line = lanelet::geometry::toArcCoordinates( lanelet::utils::to2D(llt.centerline()), - lanelet::utils::to2D(lanelet_stop_lines).front().basicPoint()); + lanelet::utils::to2D(lanelet_stop_lines.value()).front().basicPoint()); return distance + to_stop_line.length - to_object.length; }