From 5d79e0ac2fb76de764b109550decadf4af4259d4 Mon Sep 17 00:00:00 2001 From: Moritz Kobitzsch Date: Mon, 5 Sep 2016 10:06:50 +0200 Subject: [PATCH] catch infinite loops --- features/guidance/bugs.feature | 35 +++++++++++++++++++ src/engine/guidance/post_processing.cpp | 1 - .../guidance/intersection_generator.cpp | 7 ++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 features/guidance/bugs.feature diff --git a/features/guidance/bugs.feature b/features/guidance/bugs.feature new file mode 100644 index 000000000..489262c68 --- /dev/null +++ b/features/guidance/bugs.feature @@ -0,0 +1,35 @@ +@routing @guidance +Feature: Features related to bugs + + Background: + Given the profile "car" + Given a grid size of 5 meters + + @2852 + Scenario: Loop + Given the node map + | a | 1 | | g | | | b | + | | | | | | | | + | | | | | | | | + | e | | | | | | f | + | | | | | | | | + | | | | | | | 2 | + | d | | | h | | | c | + + And the ways + | nodes | name | oneway | + | agb | top | yes | + | bfc | right | yes | + | chd | bottom | yes | + | dea | left | yes | + + And the nodes + | node | highway | + | g | traffic_signals | + | f | traffic_signals | + | h | traffic_signals | + | e | traffic_signals | + + When I route I should get + | waypoints | route | turns | + | 1,2 | top,right,right | depart,new name right,arrive | diff --git a/src/engine/guidance/post_processing.cpp b/src/engine/guidance/post_processing.cpp index 5c678711b..3c847fd05 100644 --- a/src/engine/guidance/post_processing.cpp +++ b/src/engine/guidance/post_processing.cpp @@ -1158,7 +1158,6 @@ std::vector buildIntersections(std::vector steps) std::size_t last_valid_instruction = 0; for (std::size_t step_index = 0; step_index < steps.size(); ++step_index) { - const auto next_step_index = step_index + 1; auto &step = steps[step_index]; const auto instruction = step.maneuver.instruction; if (instruction.type == TurnType::Suppressed) diff --git a/src/extractor/guidance/intersection_generator.cpp b/src/extractor/guidance/intersection_generator.cpp index 049cea59e..e09fa7b48 100644 --- a/src/extractor/guidance/intersection_generator.cpp +++ b/src/extractor/guidance/intersection_generator.cpp @@ -574,6 +574,9 @@ IntersectionGenerator::GetActualNextIntersection(const NodeID starting_node, NodeID node_at_intersection = starting_node; EdgeID incoming_edge = via_edge; + // to prevent endless loops + const auto termination_node = node_based_graph.GetTarget(via_edge); + while (result.size() == 2 && node_based_graph.GetEdgeData(via_edge).IsCompatibleTo( node_based_graph.GetEdgeData(result[1].turn.eid))) @@ -581,6 +584,10 @@ IntersectionGenerator::GetActualNextIntersection(const NodeID starting_node, node_at_intersection = node_based_graph.GetTarget(incoming_edge); incoming_edge = result[1].turn.eid; result = GetConnectedRoads(node_at_intersection, incoming_edge); + + // When looping back to the original node, we obviously are in a loop. Stop there. + if (termination_node == node_based_graph.GetTarget(incoming_edge)) + break; } // return output if requested