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,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();
}