From 8e7998e19d840a8570c971e90a3961a2e9e52c66 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 27 Aug 2017 19:10:30 -0700 Subject: [PATCH] Fixed bug 3710 - SDL_OpenAudio(desired, obtained) doesn't update desired's size when obtained is NULL David Ludwig I've created a new set of patches. I am happy to create more, if it would help. One version only copies 'size'. A second version copies both 'size' and 'silence'. When looking over the documentation for SDL_OpenAudio in SDL_audio.h, it mentioned that both 'size' and 'silence' were things that SDL_OpenAudio would calculate. Regarding *both* patches, I did notice that SDL 1.2 appears to have always modified desired's size and silence fields. The SDL wiki, at https://wiki.libsdl.org/SDL_OpenAudio#Remarks , does note: --- src/audio/SDL_audio.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 120555f9c222c..aabaf1214ce6a 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -1413,7 +1413,14 @@ SDL_OpenAudio(SDL_AudioSpec * desired, SDL_AudioSpec * obtained) id = open_audio_device(NULL, 0, desired, obtained, SDL_AUDIO_ALLOW_ANY_CHANGE, 1); } else { - id = open_audio_device(NULL, 0, desired, NULL, 0, 1); + SDL_AudioSpec _obtained; + SDL_zero(_obtained); + id = open_audio_device(NULL, 0, desired, &_obtained, 0, 1); + /* On successful open, copy calculated values into 'desired'. */ + if (id > 0) { + desired->size = _obtained.size; + desired->silence = _obtained.silence; + } } SDL_assert((id == 0) || (id == 1));