Skip to content

Commit

Permalink
Fixed bug 4169 - Crash due to audio session observer race condition
Browse files Browse the repository at this point in the history
Jona

The following explains why this bug was happening:
This crash was caused because the audio session was being set as active [session setActive:YES error:&err] when the audio device was actually being CLOSED. Certain cases the audio session being set to active would fail and the method would return right away. Because of the way the error was handled we never removed the SDLInterruptionListener thus leaking it. Later when an interruption was received the THIS_ object would contain a pointer to an already released device causing the crash.

The fix:
When only one device remained open and it was being closed we needed to set the audio session as NOT active and completely ignore the returned error to successfully release the SDLInterruptionListener. I think the user assumed that the open_playback_devices and open_capture_devices would equal 0 when all of them where closed but the truth is that at the end of the closing process that the open devices count is decremented.
  • Loading branch information
slouken committed May 24, 2018
1 parent b3173d9 commit 8325df2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/audio/coreaudio/SDL_coreaudio.m
Expand Up @@ -355,7 +355,7 @@ static BOOL update_audio_session(_THIS, SDL_bool open)
return NO;
}

if (open_playback_devices + open_capture_devices == 1) {
if (open && (open_playback_devices + open_capture_devices) == 1) {
if (![session setActive:YES error:&err]) {
NSString *desc = err.description;
SDL_SetError("Could not activate Audio Session: %s", desc.UTF8String);
Expand Down Expand Up @@ -392,10 +392,10 @@ static BOOL update_audio_session(_THIS, SDL_bool open)
if (this->hidden->interruption_listener != NULL) {
SDLInterruptionListener *listener = nil;
listener = (SDLInterruptionListener *) CFBridgingRelease(this->hidden->interruption_listener);
[center removeObserver:listener];
@synchronized (listener) {
listener.device = NULL;
}
[center removeObserver:listener];
}
}
}
Expand Down

0 comments on commit 8325df2

Please sign in to comment.