Skip to content

Commit c0346d5

Browse files
k-hazama-esolPanConChicharron
authored andcommitted
fix(autoware_crosswalk_traffic_light_estimator): add process that guard access to empty elements (autowarefoundation#10281)
* fix(autoware_crosswalk_traffic_light_estimator) : add process that guard access to empty elements. Signed-off-by: k-hazama-esol <[email protected]> * fix for linter Signed-off-by: k-hazama-esol <[email protected]> --------- Signed-off-by: k-hazama-esol <[email protected]>
1 parent fe609ee commit c0346d5

File tree

1 file changed

+10
-2
lines changed
  • perception/autoware_crosswalk_traffic_light_estimator/src

1 file changed

+10
-2
lines changed

perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,11 @@ void CrosswalkTrafficLightEstimatorNode::setCrosswalkTrafficSignal(
303303
output_traffic_signal_element.color = color;
304304
output_traffic_signal_element.shape = TrafficSignalElement::CIRCLE;
305305
output_traffic_signal_element.confidence = 1.0;
306-
output.traffic_light_groups[idx].elements[0] = output_traffic_signal_element;
306+
if (output.traffic_light_groups[idx].elements.empty()) {
307+
output.traffic_light_groups[idx].elements.push_back(output_traffic_signal_element);
308+
} else {
309+
output.traffic_light_groups[idx].elements[0] = output_traffic_signal_element;
310+
}
307311
continue;
308312
}
309313
updateFlashingState(signal); // check if it is flashing
@@ -325,6 +329,10 @@ void CrosswalkTrafficLightEstimatorNode::setCrosswalkTrafficSignal(
325329
bool CrosswalkTrafficLightEstimatorNode::isInvalidDetectionStatus(
326330
const TrafficSignal & signal) const
327331
{
332+
// invalid if elements is empty
333+
if (signal.elements.empty()) {
334+
return true;
335+
}
328336
// check occlusion, backlight(shape is unknown) and no detection(shape is circle)
329337
if (
330338
signal.elements.front().color == TrafficSignalElement::UNKNOWN &&
@@ -347,7 +355,7 @@ void CrosswalkTrafficLightEstimatorNode::updateFlashingState(const TrafficSignal
347355

348356
// flashing green
349357
if (
350-
signal.elements.front().color == TrafficSignalElement::UNKNOWN &&
358+
!signal.elements.empty() && signal.elements.front().color == TrafficSignalElement::UNKNOWN &&
351359
signal.elements.front().confidence != 0 && // not due to occlusion
352360
current_color_state_.at(id) != TrafficSignalElement::UNKNOWN) {
353361
is_flashing_.at(id) = true;

0 commit comments

Comments
 (0)