From 488916b51ce680addee3bf334a3d9b3d8d781f44 Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 12 Apr 2021 12:18:11 -0700 Subject: [PATCH] Process queued music after processing fades While fixing all the other music bugs, I discovered that starting playtesting in the editor wouldn't play the level music. The problem is that the editor playtesting start code calls music.fadeout() before calling music.play(). This queues up the track from the music.play() call. After that, what should happen is that processmusic() processes the fade, the fade is then finished, and then after that it sees that the music is halted so it can play the queued track. Instead what happens is that the function first attempts to play the music before the fade is processed and finished, so play() will re-queue the music again, but the queue gets cleared right after that (this is a subtle bit of behavior - it means if the game fails to play a queued track due to it fading, it's not going to re-queue it again and end up in some sort of infinite loop). This is a frame ordering issue - the function is tripping over itself when it shouldn't be. To fix it, just put the queue processing code after the fade processing code. --- desktop_version/src/Music.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/desktop_version/src/Music.cpp b/desktop_version/src/Music.cpp index e376b503..f69d054f 100644 --- a/desktop_version/src/Music.cpp +++ b/desktop_version/src/Music.cpp @@ -341,13 +341,6 @@ void musicclass::processmusic(void) return; } - if (nicefade && Mix_PausedMusic() == 1) - { - play(nicechange); - nicechange = -1; - nicefade = false; - } - if(m_doFadeInVol) { processmusicfadein(); @@ -357,6 +350,14 @@ void musicclass::processmusic(void) { processmusicfadeout(); } + + /* This needs to come after processing fades */ + if (nicefade && Mix_PausedMusic() == 1) + { + play(nicechange); + nicechange = -1; + nicefade = false; + } }