From 1226ee06c3502726188f63672b08697f711385c4 Mon Sep 17 00:00:00 2001 From: forteri76 Date: Tue, 14 Apr 2015 14:19:02 +0000 Subject: [PATCH] Fixed a null pointer exception bug related to pausing the music player when stopping the player thread. --- AndroidManifest.xml | 4 ++-- jni/jni_stubs.cpp | 1 - .../andmodplug/PlayerThread.java | 22 +++++++++++++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 20ef7fe..15b31e6 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="37" + android:versionName="3.4"> GetByteArrayElements(buffer, 0); currmodFile = ModPlug_Load(bytes, csize); env->ReleaseByteArrayElements(buffer, bytes, 0); - env->DeleteLocalRef(buffer); DIABpatternchanged = 0; ANDMODPLUGpatternfrom = 0; diff --git a/src/com/peculiargames/andmodplug/PlayerThread.java b/src/com/peculiargames/andmodplug/PlayerThread.java index 32d5eee..7d3d949 100644 --- a/src/com/peculiargames/andmodplug/PlayerThread.java +++ b/src/com/peculiargames/andmodplug/PlayerThread.java @@ -572,14 +572,23 @@ public boolean pausePlay(boolean immediate) { if (mMyTrack.getState() == AudioTrack.STATE_INITIALIZED) try { if (immediate) { mMyTrack.pause(); - mMyTrack.flush(); - mFlushed = true; + if (mMyTrack != null) { + mMyTrack.flush(); + mFlushed = true; + } } else { mMyTrack.stop(); } paused = true; - } catch (IllegalStateException ise) { + } catch (NullPointerException npe) { + /* + * mMyTrack may be destroyed in a different process, so the + * slim possibility exists that we may invoke it when it has + * been nullified. + */ + } + catch (IllegalStateException ise) { /* * Nothing to do here, so just try to continue gracefully. */ @@ -800,11 +809,16 @@ public void startPaused(boolean flag) { * the native player library and de-allocate all resources it used. */ public void stopThread() { + /* + * Music playback must be paused before stopping the thread. Force + * a flush of the audio data to immediately stop audio playback. + */ + pausePlay(true); + /* * Stops the music player thread (see run() above). */ mRunning = false; - pausePlay(true); /* * Interrupt the thread if it is sleeping or waiting.