Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(autoware_crosswalk_traffic_light_estimator): add process that guard access to empty elements #10281

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@
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);

Check warning on line 307 in perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp#L307

Added line #L307 was not covered by tests
} else {
output.traffic_light_groups[idx].elements[0] = output_traffic_signal_element;

Check warning on line 309 in perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp#L309

Added line #L309 was not covered by tests
}

Check warning on line 310 in perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Deep, Nested Complexity

CrosswalkTrafficLightEstimatorNode::setCrosswalkTrafficSignal has a nested complexity depth of 4, threshold = 4. This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health.
continue;
}
updateFlashingState(signal); // check if it is flashing
Expand All @@ -325,6 +329,10 @@
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 &&
Expand All @@ -347,7 +355,7 @@

// flashing green
if (
signal.elements.front().color == TrafficSignalElement::UNKNOWN &&
!signal.elements.empty() && signal.elements.front().color == TrafficSignalElement::UNKNOWN &&

Check warning on line 358 in perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Conditional

CrosswalkTrafficLightEstimatorNode::updateFlashingState increases from 1 complex conditionals with 2 branches to 1 complex conditionals with 3 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.

Check warning on line 358 in perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp

View check run for this annotation

Codecov / codecov/patch

perception/autoware_crosswalk_traffic_light_estimator/src/node.cpp#L358

Added line #L358 was not covered by tests
signal.elements.front().confidence != 0 && // not due to occlusion
current_color_state_.at(id) != TrafficSignalElement::UNKNOWN) {
is_flashing_.at(id) = true;
Expand Down
Loading