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

View File

@@ -129,15 +129,16 @@ 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() {
synchronized (Music.INSTANCE) {
if (trackList == null || trackList.length == 0 || player.isLooping() || music != player){
return;
}
Music.this.stop();
if (trackQueue.isEmpty()) {
@@ -155,6 +156,7 @@ public enum Music {
play(trackQueue.remove(0), trackLooper);
}
}
}.start();
}
};