Skip to content

Commit

Permalink
coreaudio: Don't crash on shutdown in a race condition.
Browse files Browse the repository at this point in the history
Fixed #6159.
(cherry picked from commit 411582c)
  • Loading branch information
icculus authored and sezero committed Sep 28, 2022
1 parent 128c34b commit d6e939d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/audio/coreaudio/SDL_coreaudio.m
Expand Up @@ -523,8 +523,16 @@ static BOOL update_audio_session(_THIS, SDL_bool open, SDL_bool allow_playandrec
{
SDL_AudioDevice *this = (SDL_AudioDevice *) inUserData;

/* This flag is set before this->mixer_lock is destroyed during
shutdown, so check it before grabbing the mutex, and then check it
again _after_ in case we blocked waiting on the lock. */
if (SDL_AtomicGet(&this->shutdown)) {
return; /* don't do anything, since we don't even want to enqueue this buffer again. */
}

SDL_LockMutex(this->mixer_lock);

/* !!! FIXME: why do we have this->hidden->shutdown when this->shutdown exists? */
if (SDL_AtomicGet(&this->hidden->shutdown)) {
SDL_UnlockMutex(this->mixer_lock);
return; /* don't do anything, since we don't even want to enqueue this buffer again. */
Expand Down

0 comments on commit d6e939d

Please sign in to comment.