@@ -1391,6 +1391,7 @@ static int SDLCALL RecordingAudioThread(void *devicep) // thread entry point
13911391typedef struct CountAudioDevicesData
13921392{
13931393 int devs_seen ;
1394+ int devs_skipped ;
13941395 const int num_devices ;
13951396 SDL_AudioDeviceID * result ;
13961397 const bool recording ;
@@ -1406,7 +1407,13 @@ static bool SDLCALL CountAudioDevices(void *userdata, const SDL_HashTable *table
14061407 const bool isphysical = !!(devid & (1 <<1 ));
14071408 if (isphysical && (devid_recording == data -> recording )) {
14081409 SDL_assert (data -> devs_seen < data -> num_devices );
1409- data -> result [data -> devs_seen ++ ] = devid ;
1410+ SDL_AudioDevice * device = (SDL_AudioDevice * ) value ; // this is normally risky, but we hold the device_hash_lock here.
1411+ const bool zombie = SDL_GetAtomicInt (& device -> zombie ) != 0 ;
1412+ if (zombie ) {
1413+ data -> devs_skipped ++ ;
1414+ } else {
1415+ data -> result [data -> devs_seen ++ ] = devid ;
1416+ }
14101417 }
14111418 return true; // keep iterating.
14121419}
@@ -1422,10 +1429,11 @@ static SDL_AudioDeviceID *GetAudioDevices(int *count, bool recording)
14221429 num_devices = SDL_GetAtomicInt (recording ? & current_audio .recording_device_count : & current_audio .playback_device_count );
14231430 result = (SDL_AudioDeviceID * ) SDL_malloc ((num_devices + 1 ) * sizeof (SDL_AudioDeviceID ));
14241431 if (result ) {
1425- CountAudioDevicesData data = { 0 , num_devices , result , recording };
1432+ CountAudioDevicesData data = { 0 , 0 , num_devices , result , recording };
14261433 SDL_IterateHashTable (current_audio .device_hash , CountAudioDevices , & data );
1427- SDL_assert (data .devs_seen == num_devices );
1428- result [data .devs_seen ] = 0 ; // null-terminated.
1434+ SDL_assert ((data .devs_seen + data .devs_skipped ) == num_devices );
1435+ num_devices = data .devs_seen ; // might be less if we skipped any.
1436+ result [num_devices ] = 0 ; // null-terminated.
14291437 }
14301438 }
14311439 SDL_UnlockRWLock (current_audio .device_hash_lock );
@@ -1567,7 +1575,9 @@ int *SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int *count)
15671575 SDL_AudioDevice * device = ObtainPhysicalAudioDeviceDefaultAllowed (devid );
15681576 if (device ) {
15691577 channels = device -> spec .channels ;
1570- result = SDL_ChannelMapDup (device -> chmap , channels );
1578+ if (channels > 0 && device -> chmap ) {
1579+ result = SDL_ChannelMapDup (device -> chmap , channels );
1580+ }
15711581 }
15721582 ReleaseAudioDevice (device );
15731583
0 commit comments