From df54b93c49626a3abce9d482b7aa710e80d7774e Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 27 Aug 2021 14:43:46 -0400 Subject: [PATCH] v1.0.2: added a missing sync check in music to prevent crashes --- .../java/com/watabou/noosa/audio/Music.java | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/SPD-classes/src/main/java/com/watabou/noosa/audio/Music.java b/SPD-classes/src/main/java/com/watabou/noosa/audio/Music.java index 2b909dd51..bc6e3bc19 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/audio/Music.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/audio/Music.java @@ -129,31 +129,33 @@ public enum Music { private com.badlogic.gdx.audio.Music.OnCompletionListener trackLooper = new com.badlogic.gdx.audio.Music.OnCompletionListener() { @Override public void onCompletion(com.badlogic.gdx.audio.Music music) { - if (trackList == null || trackList.length == 0 || player.isLooping() || music != player){ - return; - } - //we do this in a separate thread to avoid graphics hitching while the music is prepared //FIXME this fixes graphics stutter but there's still some audio stutter, perhaps keep more than 1 player alive? new Thread(){ @Override public void run() { - Music.this.stop(); - - if (trackQueue.isEmpty()){ - for (int i = 0; i < trackList.length; i++){ - if (Random.Float() < trackChances[i]){ - trackQueue.add(trackList[i]); - } + synchronized (Music.INSTANCE) { + if (trackList == null || trackList.length == 0 || player.isLooping() || music != player){ + return; } - if (shuffle) Collections.shuffle(trackQueue); - } - if (!enabled || trackQueue.isEmpty()){ - return; - } + Music.this.stop(); - play(trackQueue.remove(0), trackLooper); + if (trackQueue.isEmpty()) { + for (int i = 0; i < trackList.length; i++) { + if (Random.Float() < trackChances[i]) { + trackQueue.add(trackList[i]); + } + } + if (shuffle) Collections.shuffle(trackQueue); + } + + if (!enabled || trackQueue.isEmpty()) { + return; + } + + play(trackQueue.remove(0), trackLooper); + } } }.start(); }