SDL: audio: Fix crash calling SDL_OpenAudio() after SDL_AudioInit() fails

From 704edf632394079c1df61d14ed5aa824432878ae Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Fri, 12 Nov 2021 17:07:22 -0600
Subject: [PATCH] audio: Fix crash calling SDL_OpenAudio() after
 SDL_AudioInit() fails

The SDL_WasInit() checks don't work when using SDL_AudioInit() directly,
which is exactly what audio_initOpenCloseQuitAudio() in testautomation
does.
---
 src/audio/SDL_audio.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 5241c8ee10..5d8697655d 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -960,7 +960,7 @@ SDL_AudioInit(const char *driver_name)
     int initialized = 0;
     int tried_to_init = 0;
 
-    if (SDL_WasInit(SDL_INIT_AUDIO)) {
+    if (SDL_GetCurrentAudioDriver()) {
         SDL_AudioQuit();        /* shutdown driver if already running. */
     }
 
@@ -1091,7 +1091,7 @@ SDL_GetNumAudioDevices(int iscapture)
 {
     int retval = 0;
 
-    if (!SDL_WasInit(SDL_INIT_AUDIO)) {
+    if (!SDL_GetCurrentAudioDriver()) {
         return -1;
     }
 
@@ -1116,7 +1116,7 @@ SDL_GetAudioDeviceName(int index, int iscapture)
 {
     const char *retval = NULL;
 
-    if (!SDL_WasInit(SDL_INIT_AUDIO)) {
+    if (!SDL_GetCurrentAudioDriver()) {
         SDL_SetError("Audio subsystem is not initialized");
         return NULL;
     }
@@ -1160,7 +1160,7 @@ SDL_GetAudioDeviceSpec(int index, int iscapture, SDL_AudioSpec *spec)
 
     SDL_zerop(spec);
 
-    if (!SDL_WasInit(SDL_INIT_AUDIO)) {
+    if (!SDL_GetCurrentAudioDriver()) {
         return SDL_SetError("Audio subsystem is not initialized");
     }
 
@@ -1308,7 +1308,7 @@ open_audio_device(const char *devname, int iscapture,
     void *handle = NULL;
     int i = 0;
 
-    if (!SDL_WasInit(SDL_INIT_AUDIO)) {
+    if (!SDL_GetCurrentAudioDriver()) {
         SDL_SetError("Audio subsystem is not initialized");
         return 0;
     }