From 808f8e2127a970d1976176ff0a48d167a06554fd Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 8 Aug 2023 21:48:19 -0400
Subject: [PATCH] audio: Ignore 0-byte audiostream callbacks and clear streams
on (un)pause.
Reference Issue #94.
---
src/sdl2_compat.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index d7b70ad..674c1a1 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -3792,6 +3792,10 @@ static void SDLCALL SDL2AudioDeviceQueueingCallback(SDL_AudioStream *stream3, in
SDL_assert(stream3 == stream2->stream3);
SDL_assert(stream2->dataqueue3 != NULL);
+ if (approx_request == 0) {
+ return; /* nothing to do right now. */
+ }
+
buffer = (Uint8 *) SDL3_malloc(approx_request);
if (!buffer) {
return; /* oh well */
@@ -3817,6 +3821,10 @@ static void SDLCALL SDL2AudioDeviceCallbackBridge(SDL_AudioStream *stream3, int
SDL2_AudioStream *stream2 = (SDL2_AudioStream *) userdata;
Uint8 *buffer;
+ if (approx_request == 0) {
+ return; /* nothing to do right now. */
+ }
+
SDL_assert(stream2 != NULL);
SDL_assert(stream3 == stream2->stream3);
SDL_assert(stream2->dataqueue3 == NULL);
@@ -4275,6 +4283,7 @@ SDL_PauseAudioDevice(SDL_AudioDeviceID dev, int pause_on)
SDL2_AudioStream *stream2 = GetOpenAudioDevice(dev);
if (stream2) {
const SDL_AudioDeviceID device3 = SDL3_GetAudioStreamBinding(stream2->stream3);
+ SDL3_ClearAudioStream(stream2->stream3);
if (device3) {
if (pause_on) {
SDL3_PauseAudioDevice(device3);