From 7099e660a6b2b61822575f06755ee998f0fc67fa Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 27 May 2022 16:01:54 -0700
Subject: [PATCH] Allow more than one cycle with no music data
Apparently libmad needs up to 4 cycles. We just want this to catch infinite loops, so using a larger number is fine.
Fixes https://github.com/libsdl-org/SDL_mixer/issues/402
---
src/music.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/music.c b/src/music.c
index 7ca56f5d..304b1fac 100644
--- a/src/music.c
+++ b/src/music.c
@@ -289,6 +289,7 @@ int music_pcm_getaudio(void *context, void *data, int bytes, int volume,
Uint8 *dst;
int len = bytes;
int zero_cycles = 0;
+ const int MAX_ZERO_CYCLES = 10; /* just try to catch infinite loops */
SDL_bool done = SDL_FALSE;
if (volume == MIX_MAX_VOLUME) {
@@ -303,8 +304,8 @@ int music_pcm_getaudio(void *context, void *data, int bytes, int volume,
}
if (consumed == 0) {
++zero_cycles;
- if (zero_cycles > 1) {
- /* We went more than one cycle with no data, we're done */
+ if (zero_cycles > MAX_ZERO_CYCLES) {
+ /* We went too many cycles with no data, we're done */
done = SDL_TRUE;
}
continue;