Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Protect SDL_PauseAudio*() with the audio callback lock.
Browse files Browse the repository at this point in the history
Otherwise, you can pause audio and still have the callback running, or run
 one more time. This makes sure the callback is definitely stopped by the
 time you return from SDL_PauseAudio().
  • Loading branch information
icculus committed Jul 14, 2013
1 parent e4a866c commit d6f37e0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/audio/SDL_audio.c
Expand Up @@ -480,13 +480,13 @@ SDL_RunAudio(void *devicep)
}
}

SDL_LockMutex(device->mixer_lock);
if (device->paused) {
SDL_memset(stream, silence, stream_len);
} else {
SDL_LockMutex(device->mixer_lock);
(*fill) (udata, stream, stream_len);
SDL_UnlockMutex(device->mixer_lock);
}
SDL_UnlockMutex(device->mixer_lock);

/* Convert the audio if necessary */
if (device->convert.needed) {
Expand Down Expand Up @@ -1114,7 +1114,9 @@ SDL_PauseAudioDevice(SDL_AudioDeviceID devid, int pause_on)
{
SDL_AudioDevice *device = get_audio_device(devid);
if (device) {
current_audio.impl.LockDevice(device);
device->paused = pause_on;
current_audio.impl.UnlockDevice(device);
}
}

Expand Down

0 comments on commit d6f37e0

Please sign in to comment.