v1.0.2: added a missing sync check in music to prevent crashes

This commit is contained in:
Evan Debenham
2021-08-27 14:43:46 -04:00
parent 4b0e89af2e
commit df54b93c49
@@ -129,32 +129,34 @@ public enum Music {
private com.badlogic.gdx.audio.Music.OnCompletionListener trackLooper = new com.badlogic.gdx.audio.Music.OnCompletionListener() { private com.badlogic.gdx.audio.Music.OnCompletionListener trackLooper = new com.badlogic.gdx.audio.Music.OnCompletionListener() {
@Override @Override
public void onCompletion(com.badlogic.gdx.audio.Music music) { 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 //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? //FIXME this fixes graphics stutter but there's still some audio stutter, perhaps keep more than 1 player alive?
new Thread(){ new Thread(){
@Override @Override
public void run() { public void run() {
synchronized (Music.INSTANCE) {
if (trackList == null || trackList.length == 0 || player.isLooping() || music != player){
return;
}
Music.this.stop(); Music.this.stop();
if (trackQueue.isEmpty()){ if (trackQueue.isEmpty()) {
for (int i = 0; i < trackList.length; i++){ for (int i = 0; i < trackList.length; i++) {
if (Random.Float() < trackChances[i]){ if (Random.Float() < trackChances[i]) {
trackQueue.add(trackList[i]); trackQueue.add(trackList[i]);
} }
} }
if (shuffle) Collections.shuffle(trackQueue); if (shuffle) Collections.shuffle(trackQueue);
} }
if (!enabled || trackQueue.isEmpty()){ if (!enabled || trackQueue.isEmpty()) {
return; return;
} }
play(trackQueue.remove(0), trackLooper); play(trackQueue.remove(0), trackLooper);
} }
}
}.start(); }.start();
} }
}; };