From 5c7eef3756ed2814fdc8e5e42a2ebed489c37405 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Sun, 16 Oct 2022 03:14:52 -0400 Subject: [PATCH 1/3] sdl2_sink: Check for null string when loading SDL audio devices Attempting to place a null string into a vector of strings causes an error that closes the application. Don't. --- src/audio_core/sink/sdl2_sink.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/audio_core/sink/sdl2_sink.cpp b/src/audio_core/sink/sdl2_sink.cpp index f12ebf7fe..dee47cf0e 100644 --- a/src/audio_core/sink/sdl2_sink.cpp +++ b/src/audio_core/sink/sdl2_sink.cpp @@ -230,7 +230,10 @@ std::vector ListSDLSinkDevices(bool capture) { const int device_count = SDL_GetNumAudioDevices(capture); for (int i = 0; i < device_count; ++i) { - device_list.emplace_back(SDL_GetAudioDeviceName(i, 0)); + const char* name = SDL_GetAudioDeviceName(i, 0); + if (name != nullptr) { + device_list.emplace_back(name); + } } return device_list; From 9fe077635e00aba362034a694c5d1a701abc288a Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Sun, 16 Oct 2022 03:15:54 -0400 Subject: [PATCH 2/3] sdl2_sink: Distinguish between capture and non-capture device names The function prototype appears to care whether we are loading capture devices or not, and SDL_GetAudioDeviceName has a parameter to use it, but for some reason it isn't. This puts `capture` where it goes. --- src/audio_core/sink/sdl2_sink.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/audio_core/sink/sdl2_sink.cpp b/src/audio_core/sink/sdl2_sink.cpp index dee47cf0e..cc13c6254 100644 --- a/src/audio_core/sink/sdl2_sink.cpp +++ b/src/audio_core/sink/sdl2_sink.cpp @@ -230,7 +230,7 @@ std::vector ListSDLSinkDevices(bool capture) { const int device_count = SDL_GetNumAudioDevices(capture); for (int i = 0; i < device_count; ++i) { - const char* name = SDL_GetAudioDeviceName(i, 0); + const char* name = SDL_GetAudioDeviceName(i, capture); if (name != nullptr) { device_list.emplace_back(name); } From 4b773b15a6cb7d78d7a9d71cf0f73fb5af591cba Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Sun, 16 Oct 2022 20:37:11 -0400 Subject: [PATCH 3/3] sdl2_sink: Inline variable init into if condition Co-authored-by: Mai --- src/audio_core/sink/sdl2_sink.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/audio_core/sink/sdl2_sink.cpp b/src/audio_core/sink/sdl2_sink.cpp index cc13c6254..c138dc628 100644 --- a/src/audio_core/sink/sdl2_sink.cpp +++ b/src/audio_core/sink/sdl2_sink.cpp @@ -230,8 +230,7 @@ std::vector ListSDLSinkDevices(bool capture) { const int device_count = SDL_GetNumAudioDevices(capture); for (int i = 0; i < device_count; ++i) { - const char* name = SDL_GetAudioDeviceName(i, capture); - if (name != nullptr) { + if (const char* name = SDL_GetAudioDeviceName(i, capture)) { device_list.emplace_back(name); } }