SDL: wasapi: If device is marked as a zombie, don't try to resuscitate it.

From ce3be02b48b60f4db6638c384792004f14ae7980 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 27 Oct 2023 01:27:22 -0400
Subject: [PATCH] wasapi: If device is marked as a zombie, don't try to
 resuscitate it.

---
 src/audio/SDL_audio.c         | 1 +
 src/audio/wasapi/SDL_wasapi.c | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 456ce44fbbb6..410b5c368c5e 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -514,6 +514,7 @@ void SDL_AudioDeviceDisconnected(SDL_AudioDevice *device)
 
     // on default devices, dump any logical devices that explicitly opened this device. Things that opened the system default can stay.
     // on non-default devices, dump everything.
+    // (by "dump" we mean send a REMOVED event; the zombie will keep consuming audio data for these logical devices until explicitly closed.)
     for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev != NULL; logdev = logdev->next) {
         if (!is_default_device || !logdev->opened_as_default) {  // if opened as a default, leave it on the zombie device for later migration.
             SDL_PendingAudioDeviceEvent *p = (SDL_PendingAudioDeviceEvent *) SDL_malloc(sizeof (SDL_PendingAudioDeviceEvent));
diff --git a/src/audio/wasapi/SDL_wasapi.c b/src/audio/wasapi/SDL_wasapi.c
index f68fb0f694e6..ffbeeec343c4 100644
--- a/src/audio/wasapi/SDL_wasapi.c
+++ b/src/audio/wasapi/SDL_wasapi.c
@@ -397,6 +397,8 @@ static SDL_bool RecoverWasapiIfLost(SDL_AudioDevice *device)
         WASAPI_DisconnectDevice(device);
         SDL_assert(SDL_AtomicGet(&device->shutdown));  // so we don't come back through here.
         return SDL_FALSE; // already failed.
+    } else if (SDL_AtomicGet(&device->zombie)) {
+        return SDL_FALSE;  // we're already dead, so just leave and let the Zombie implementations take over.
     } else if (!device->hidden->client) {
         return SDL_TRUE; // still waiting for activation.
     }