@@ -673,7 +673,21 @@ static OSStatus default_device_changed(AudioObjectID inObjectID, UInt32 inNumber
673673#if DEBUG_COREAUDIO
674674 printf (" COREAUDIO: default device changed for SDL audio device %p !\n " , this);
675675#endif
676- SDL_AtomicSet (&this->hidden ->device_change_flag , 1 ); /* let the audioqueue thread pick up on this when safe to do so. */
676+
677+ /* due to a bug (?) in CoreAudio, this seems able to fire for a device pointer that's already closed, so check our list to make sure
678+ the pointer is still valid before touching it. https://github.com/libsdl-org/SDL/issues/10432 */
679+ if (open_devices) {
680+ int i;
681+ for (i = 0 ; i < num_open_devices; i++) {
682+ SDL_AudioDevice *device = open_devices[i];
683+ if (device == this) {
684+ if (this->hidden ) {
685+ SDL_AtomicSet (&this->hidden ->device_change_flag , 1 ); /* let the audioqueue thread pick up on this when safe to do so. */
686+ }
687+ return noErr;
688+ }
689+ }
690+ }
677691 return noErr;
678692}
679693#endif
@@ -880,14 +894,25 @@ static int prepare_audioqueue(_THIS)
880894 // L R C LFE Ls Rs
881895 layout.mChannelLayoutTag = kAudioChannelLayoutTag_DVD_12 ;
882896 break ;
897+ #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000) || \
898+ (defined (MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= 101500 )
883899 case 7 :
884900 // L R C LFE Cs Ls Rs
885- layout.mChannelLayoutTag = kAudioChannelLayoutTag_WAVE_6_1 ;
901+ if (@available (macOS 10.15 , iOS 13 , *)) {
902+ layout.mChannelLayoutTag = kAudioChannelLayoutTag_WAVE_6_1 ;
903+ } else {
904+ return SDL_SetError (" Unsupported audio channels" );
905+ }
886906 break ;
887907 case 8 :
888908 // L R C LFE Rls Rrs Ls Rs
889- layout.mChannelLayoutTag = kAudioChannelLayoutTag_WAVE_7_1 ;
909+ if (@available (macOS 10.15 , iOS 13 , *)) {
910+ layout.mChannelLayoutTag = kAudioChannelLayoutTag_WAVE_7_1 ;
911+ } else {
912+ return SDL_SetError (" Unsupported audio channels" );
913+ }
890914 break ;
915+ #endif
891916 default :
892917 return SDL_SetError (" Unsupported audio channels" );
893918 }
0 commit comments