From 6bed5fc88c58159a60dea5354d1ec2f5ae6519e6 Mon Sep 17 00:00:00 2001 From: Misa Date: Fri, 14 Aug 2020 02:15:09 -0700 Subject: [PATCH] Check divisor in musicclass::play() Previously, it was assuming that the number of PPPPPP/MMMMMM tracks would always be 16, since if that wasn't the case... then the game would rudely and abruptly segfault when attempting to load the file. Huh. But now that the game properly deals with invalid headers, it's possible for the number of tracks to be 0. So I'll need to remove this assumption. --- desktop_version/src/Music.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/desktop_version/src/Music.cpp b/desktop_version/src/Music.cpp index 5f3d9070..7bc0adc7 100644 --- a/desktop_version/src/Music.cpp +++ b/desktop_version/src/Music.cpp @@ -151,12 +151,15 @@ void songend() void musicclass::play(int t, const double position_sec /*= 0.0*/, const int fadein_ms /*= 3000*/) { - // No need to check if num_tracks is greater than 0, we wouldn't be here if it wasn't if (mmmmmm && usingmmmmmm) { - t %= num_mmmmmm_tracks; + // Don't conjoin this if-statement with the above one... + if (num_mmmmmm_tracks > 0) + { + t %= num_mmmmmm_tracks; + } } - else + else if (num_pppppp_tracks > 0) { t %= num_pppppp_tracks; }