Skip to content

Commit 0882623

Browse files
committed
Clamp the audio drain delay to 100 ms
Fixes #9829
1 parent 889e478 commit 0882623

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
@@ -1298,7 +1298,11 @@ void SDL_PlaybackAudioThreadShutdown(SDL_AudioDevice *device)
12981298
const int frames = device->buffer_size / SDL_AUDIO_FRAMESIZE(device->spec);
12991299
// Wait for the audio to drain if device didn't die.
13001300
if (!SDL_GetAtomicInt(&device->zombie)) {
1301-
SDL_Delay(((frames * 1000) / device->spec.freq) * 2);
1301+
int delay = ((frames * 1000) / device->spec.freq) * 2;
1302+
if (delay > 100) {
1303+
delay = 100;
1304+
}
1305+
SDL_Delay(delay);
13021306
}
13031307
current_audio.impl.ThreadDeinit(device);
13041308
SDL_AudioThreadFinalize(device);

src/audio/alsa/SDL_alsa_audio.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,11 @@ static void ALSA_CloseDevice(SDL_AudioDevice *device)
485485
if (device->hidden) {
486486
if (device->hidden->pcm) {
487487
// Wait for the submitted audio to drain. ALSA_snd_pcm_drop() can hang, so don't use that.
488-
SDL_Delay(((device->sample_frames * 1000) / device->spec.freq) * 2);
488+
int delay = ((device->sample_frames * 1000) / device->spec.freq) * 2;
489+
if (delay > 100) {
490+
delay = 100;
491+
}
492+
SDL_Delay(delay);
489493
ALSA_snd_pcm_close(device->hidden->pcm);
490494
}
491495
SDL_free(device->hidden->mixbuf);

0 commit comments

Comments
 (0)