Commit c5b21ea6c10defa5b22debdd56f46019f74c0a4e

Ryan C. Gordon 2014-07-30T11:11:48

SDL_GetQueuedAudioSize() shouldn't grab lock when not set up for queueing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 804138c..7559d6c 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -472,11 +472,11 @@ SDL_QueueAudio(SDL_AudioDeviceID devid, const void *_data, Uint32 len)
 Uint32
 SDL_GetQueuedAudioSize(SDL_AudioDeviceID devid)
 {
-    /* this happens to work for non-queueing devices, since we memset()
-       the device to zero at init time, and these devices should return 0. */
     Uint32 retval = 0;
     SDL_AudioDevice *device = get_audio_device(devid);
-    if (device) {
+
+    /* Nothing to do unless we're set up for queueing. */
+    if (device && (device->spec.callback == SDL_BufferQueueDrainCallback)) {
         current_audio.impl.LockDevice(device);
         retval = device->queued_bytes + current_audio.impl.GetPendingBytes(device);
         current_audio.impl.UnlockDevice(device);