From da731a56b5489db4f7cd72afada5423cf1081823 Mon Sep 17 00:00:00 2001 From: sonora Date: Wed, 6 Jul 2016 06:07:18 +0200 Subject: [PATCH] resolve occasional NPE --- .../net/osmand/plus/voice/TTSCommandPlayerImpl.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java b/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java index 06f9a3c715..dfba551633 100644 --- a/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java +++ b/OsmAnd/src/net/osmand/plus/voice/TTSCommandPlayerImpl.java @@ -144,19 +144,21 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer { i.putExtra("messageType", PEBBLE_ALERT); i.putExtra("sender", "OsmAnd"); i.putExtra("notificationData", notificationData); - mTtsContext.sendBroadcast(i); + if (mTtsContext != null) { + mTtsContext.sendBroadcast(i); + log.info("Send message to pebble failed" + bld.toString()); + } log.info("Send message to pebble " + bld.toString()); } private void initializeEngine(final Context ctx, final Activity act) { - if (mTts != null && mTtsContext != ctx) { + if (mTtsContext != ctx) { internalClear(); } if (mTts == null) { mTtsContext = ctx; - ttsRequests = 0; final float speechRate = cSpeechRate; mTts = new TextToSpeech(ctx, new OnInitListener() { @Override @@ -235,10 +237,10 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer { private void internalClear() { if (mTts != null) { mTts.shutdown(); - mTtsContext = null; mTts = null; - ttsRequests = 0; } + mTtsContext = null; + ttsRequests = 0; } @Override