sdl2-compat: audio: Populate the audio device lists at init time.

From 4e72b574502f77a109f5e325ca562ca228db734e Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 7 Feb 2025 11:11:55 -0500
Subject: [PATCH] audio: Populate the audio device lists at init time.

Fixes #312.
---
 src/sdl2_compat.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 891b4a4..5cdc006 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -5813,6 +5813,16 @@ SDL_InitSubSystem(Uint32 flags)
             SDL_GL_SetAttribute(SDL2_GL_BLUE_SIZE, 2);
             SDL_GL_SetAttribute(SDL2_GL_ALPHA_SIZE, 0);
         }
+
+        /* if audio was initialized and there are no devices enumerated yet, build some initial device lists. */
+        if ((flags & SDL_INIT_AUDIO) && SDL3_WasInit(SDL_INIT_AUDIO)) {
+            if (AudioSDL3PlaybackDevices.num_devices == 0) {
+                SDL_GetNumAudioDevices(SDL2_FALSE);
+            }
+            if (AudioSDL3RecordingDevices.num_devices == 0) {
+                SDL_GetNumAudioDevices(SDL2_TRUE);
+            }
+        }
     }
     return result;
 }