From 82512864c599d068d7e5a9545a469c414f829130 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 29 May 2017 22:25:18 +0200 Subject: [PATCH] Try to fix NPE while animating thread Conflicts: OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java --- .../plus/views/AnimateDraggingMapThread.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java b/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java index bbfc2dd9be..0c72a8980d 100644 --- a/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java +++ b/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java @@ -90,18 +90,19 @@ public class AnimateDraggingMapThread { public void stopAnimatingSync(){ // wait until current thread != null stopped = true; - while(currentThread != null){ + Thread tt = null; + while((tt = currentThread) != null){ try { - currentThread.join(); - } catch (InterruptedException e) { + tt.join(); + } catch (Exception e) { } } } - public void startThreadAnimating(final Runnable runnable){ + public synchronized void startThreadAnimating(final Runnable runnable){ stopAnimatingSync(); stopped = false; - currentThread = new Thread(new Runnable() { + final Thread t = new Thread(new Runnable() { @Override public void run() { @@ -114,8 +115,8 @@ public class AnimateDraggingMapThread { } } }, "Animating Thread"); - currentThread.start(); - + currentThread = t; + t.start(); } public void startMoving(final double finalLat, final double finalLon, final Pair finalZoom,