From 13b3f16bca94b3ffb5734fe9cfed64b07e57022f Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 17 Feb 2020 18:49:12 +0100 Subject: [PATCH] Fix infinite loop --- .../osmand/plus/routing/RoutingHelper.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index c7d09976cf..94dfecbab6 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -693,20 +693,27 @@ public class RoutingHelper { } if(nextPoint > 0) { - float bearingTo = currentLocation.bearingTo(routeNodes.get(nextPoint)); - Location mp = MapUtils.calculateMidPoint(routeNodes.get(nextPoint - 1), routeNodes.get(nextPoint)); - boolean found = false; - while (mp.distanceTo(routeNodes.get(nextPoint)) > 100) { + Location next = routeNodes.get(nextPoint); + Location prev = routeNodes.get(nextPoint - 1); + float bearingTo = currentLocation.bearingTo(next); + float bearingPrev = currentLocation.bearingTo(prev); + while (true) { + Location mp = MapUtils.calculateMidPoint(routeNodes.get(nextPoint - 1), routeNodes.get(nextPoint)); + if(mp.distanceTo(routeNodes.get(nextPoint)) <= 100) { + break; + } float bearingMid = currentLocation.bearingTo(mp); - if (Math.abs(MapUtils.degreesDiff(bearingMid, bearingTo)) <= ANGLE_TO_DECLINE) { - route.updateNextVisiblePoint(nextPoint, mp); - found = true; + boolean sharpTo = Math.abs(MapUtils.degreesDiff(bearingMid, bearingTo)) < ANGLE_TO_DECLINE; + boolean sharpPrev = Math.abs(MapUtils.degreesDiff(bearingMid, bearingPrev)) < ANGLE_TO_DECLINE; + if(sharpPrev) { + next = mp; + } else if(sharpTo){ + prev = mp; + } else { break; } } - if(!found) { - route.updateNextVisiblePoint(nextPoint, null); - } + route.updateNextVisiblePoint(nextPoint, next); } } @@ -922,7 +929,7 @@ public class RoutingHelper { if(l != null && l.hasSpeed()) { speed = l.getSpeed(); } - if(next != null) { + if(next != null && n.directionInfo != null) { next[0] = n.directionInfo.getTurnType(); } if(n.distanceTo > 0 && n.directionInfo != null && !n.directionInfo.getTurnType().isSkipToSpeak() &&