Skip to content

Commit

Permalink
Fixed a null pointer exception bug related to pausing the music playe…
Browse files Browse the repository at this point in the history
…r when stopping the player thread.
  • Loading branch information
forteri76 committed Apr 14, 2015
1 parent b44c418 commit 1226ee0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.jfedor.frozenbubble"
android:versionCode="36"
android:versionName="3.3">
android:versionCode="37"
android:versionName="3.4">

<supports-screens
android:smallScreens="true"
Expand Down
1 change: 0 additions & 1 deletion jni/jni_stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ JNIEXPORT jboolean JNICALL Java_com_peculiargames_andmodplug_PlayerThread_ModPlu
jbyte* bytes = env->GetByteArrayElements(buffer, 0);
currmodFile = ModPlug_Load(bytes, csize);
env->ReleaseByteArrayElements(buffer, bytes, 0);
env->DeleteLocalRef(buffer);

DIABpatternchanged = 0;
ANDMODPLUGpatternfrom = 0;
Expand Down
22 changes: 18 additions & 4 deletions src/com/peculiargames/andmodplug/PlayerThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 1226ee0

Please sign in to comment.