From 8ae2419b7127144ad37a94e4de003a3c35719dc5 Mon Sep 17 00:00:00 2001 From: k-hazama-esol Date: Fri, 14 Mar 2025 16:35:22 +0900 Subject: [PATCH 1/2] fix(autoware_crosswalk_traffic_light_estimator) : add process that guard access to empty elements. Signed-off-by: k-hazama-esol --- .../src/node.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp b/perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp index d7cc6c725edfd..0dedbd8af93b4 100644 --- a/perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp +++ b/perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp @@ -303,7 +303,11 @@ void CrosswalkTrafficLightEstimatorNode::setCrosswalkTrafficSignal( output_traffic_signal_element.color = color; output_traffic_signal_element.shape = TrafficSignalElement::CIRCLE; output_traffic_signal_element.confidence = 1.0; - output.traffic_light_groups[idx].elements[0] = output_traffic_signal_element; + if (output.traffic_light_groups[idx].elements.empty()) { + output.traffic_light_groups[idx].elements.push_back(output_traffic_signal_element); + } else { + output.traffic_light_groups[idx].elements[0] = output_traffic_signal_element; + } continue; } updateFlashingState(signal); // check if it is flashing @@ -325,6 +329,10 @@ void CrosswalkTrafficLightEstimatorNode::setCrosswalkTrafficSignal( bool CrosswalkTrafficLightEstimatorNode::isInvalidDetectionStatus( const TrafficSignal & signal) const { + // invalid if elements is empty + if (signal.elements.empty()) { + return true; + } // check occlusion, backlight(shape is unknown) and no detection(shape is circle) if ( signal.elements.front().color == TrafficSignalElement::UNKNOWN && @@ -347,6 +355,7 @@ void CrosswalkTrafficLightEstimatorNode::updateFlashingState(const TrafficSignal // flashing green if ( + !signal.elements.empty() && signal.elements.front().color == TrafficSignalElement::UNKNOWN && signal.elements.front().confidence != 0 && // not due to occlusion current_color_state_.at(id) != TrafficSignalElement::UNKNOWN) { From 8d208e711b921fd1e9f498b1f68a77661794c22d Mon Sep 17 00:00:00 2001 From: k-hazama-esol Date: Mon, 17 Mar 2025 17:27:30 +0900 Subject: [PATCH 2/2] fix for linter Signed-off-by: k-hazama-esol --- .../autoware_crosswalk_traffic_light_estimator/src/node.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp b/perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp index 0dedbd8af93b4..8e301c1bd0b60 100644 --- a/perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp +++ b/perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp @@ -329,7 +329,7 @@ void CrosswalkTrafficLightEstimatorNode::setCrosswalkTrafficSignal( bool CrosswalkTrafficLightEstimatorNode::isInvalidDetectionStatus( const TrafficSignal & signal) const { - // invalid if elements is empty + // invalid if elements is empty if (signal.elements.empty()) { return true; } @@ -355,8 +355,7 @@ void CrosswalkTrafficLightEstimatorNode::updateFlashingState(const TrafficSignal // flashing green if ( - !signal.elements.empty() && - signal.elements.front().color == TrafficSignalElement::UNKNOWN && + !signal.elements.empty() && signal.elements.front().color == TrafficSignalElement::UNKNOWN && signal.elements.front().confidence != 0 && // not due to occlusion current_color_state_.at(id) != TrafficSignalElement::UNKNOWN) { is_flashing_.at(id) = true;