Adding null checks in LocalizationStage::ExtendAndFindSafeSpace

This commit is contained in:
Praveen Kumar 2020-10-20 18:42:14 +05:30 committed by bernat
parent a90956ad0c
commit 7f6c2b3594
1 changed files with 24 additions and 10 deletions

View File

@ -234,16 +234,23 @@ void LocalizationStage::ExtendAndFindSafeSpace(const ActorId actor_id,
// Extend buffer if safe point not found. // Extend buffer if safe point not found.
if (!safe_point_found) { if (!safe_point_found) {
while (!past_junction) { bool abort = false;
current_waypoint = current_waypoint->GetNextWaypoint().front();
while (!past_junction && !abort) {
NodeList next_waypoints = current_waypoint->GetNextWaypoint();
if (!next_waypoints.empty()) {
current_waypoint = next_waypoints.front();
PushWaypoint(actor_id, track_traffic, waypoint_buffer, current_waypoint); PushWaypoint(actor_id, track_traffic, waypoint_buffer, current_waypoint);
if (!current_waypoint->CheckJunction()) { if (!current_waypoint->CheckJunction()) {
past_junction = true; past_junction = true;
junction_end_point = current_waypoint; junction_end_point = current_waypoint;
} }
} else {
abort = true;
}
} }
while (!safe_point_found) { while (!safe_point_found && !abort) {
std::vector<SimpleWaypointPtr> next_waypoints = current_waypoint->GetNextWaypoint(); std::vector<SimpleWaypointPtr> next_waypoints = current_waypoint->GetNextWaypoint();
if ((junction_end_point->DistanceSquared(current_waypoint) > safe_distance_squared) if ((junction_end_point->DistanceSquared(current_waypoint) > safe_distance_squared)
|| next_waypoints.size() > 1 || next_waypoints.size() > 1
@ -252,13 +259,20 @@ void LocalizationStage::ExtendAndFindSafeSpace(const ActorId actor_id,
safe_point_found = true; safe_point_found = true;
safe_point_after_junction = current_waypoint; safe_point_after_junction = current_waypoint;
} else { } else {
if (!next_waypoints.empty()) {
current_waypoint = next_waypoints.front(); current_waypoint = next_waypoints.front();
PushWaypoint(actor_id, track_traffic, waypoint_buffer, current_waypoint); PushWaypoint(actor_id, track_traffic, waypoint_buffer, current_waypoint);
} else {
abort = true;
}
} }
} }
} }
if (junction_begin_point->DistanceSquared(junction_end_point) < SQUARE(MIN_JUNCTION_LENGTH)) { if (junction_end_point != nullptr &&
safe_point_after_junction != nullptr &&
junction_begin_point->DistanceSquared(junction_end_point) < SQUARE(MIN_JUNCTION_LENGTH)) {
junction_end_point = nullptr; junction_end_point = nullptr;
safe_point_after_junction = nullptr; safe_point_after_junction = nullptr;
} }