Skip to content

Commit bfe046b

Browse files
committed
Clamp the audio drain delay to 100 ms
Fixes #9829 (cherry picked from commit 0882623)
1 parent 1bfa90c commit bfe046b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/audio/SDL_audio.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,11 @@ void SDL_PlaybackAudioThreadShutdown(SDL_AudioDevice *device)
12541254
const int frames = device->buffer_size / SDL_AUDIO_FRAMESIZE(device->spec);
12551255
// Wait for the audio to drain if device didn't die.
12561256
if (!SDL_GetAtomicInt(&device->zombie)) {
1257-
SDL_Delay(((frames * 1000) / device->spec.freq) * 2);
1257+
int delay = ((frames * 1000) / device->spec.freq) * 2;
1258+
if (delay > 100) {
1259+
delay = 100;
1260+
}
1261+
SDL_Delay(delay);
12581262
}
12591263
current_audio.impl.ThreadDeinit(device);
12601264
SDL_AudioThreadFinalize(device);

src/audio/alsa/SDL_alsa_audio.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,11 @@ static void ALSA_CloseDevice(SDL_AudioDevice *device)
462462
if (device->hidden) {
463463
if (device->hidden->pcm) {
464464
// Wait for the submitted audio to drain. ALSA_snd_pcm_drop() can hang, so don't use that.
465-
SDL_Delay(((device->sample_frames * 1000) / device->spec.freq) * 2);
465+
int delay = ((device->sample_frames * 1000) / device->spec.freq) * 2;
466+
if (delay > 100) {
467+
delay = 100;
468+
}
469+
SDL_Delay(delay);
466470
ALSA_snd_pcm_close(device->hidden->pcm);
467471
}
468472
SDL_free(device->hidden->mixbuf);

0 commit comments

Comments
 (0)