SDL: Fix #13276: Crash in SDL_GetAudioDeviceChannelMap

From de6a23028a2c7c05aa4f591969df1c9bb0f46003 Mon Sep 17 00:00:00 2001
From: Paul Vick <[EMAIL REDACTED]>
Date: Tue, 24 Jun 2025 22:26:14 -0700
Subject: [PATCH] Fix #13276: Crash in SDL_GetAudioDeviceChannelMap

---
 src/audio/SDL_audio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 526b4cebfc5ba..7dc247b193a75 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -1606,7 +1606,9 @@ int *SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int *count)
     SDL_AudioDevice *device = ObtainPhysicalAudioDeviceDefaultAllowed(devid);
     if (device) {
         channels = device->spec.channels;
-        result = SDL_ChannelMapDup(device->chmap, channels);
+        if (channels > 0 && device->chmap) {
+            result = SDL_ChannelMapDup(device->chmap, channels);
+        }
     }
     ReleaseAudioDevice(device);