audio: Only allocate fake_stream if we're using the standard audio threads.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 09 Aug 2016 00:44:59 -0400
changeset 10253 4a1faf81a620
parent 10252 4d99b888e7e5
child 10254 2b8bb76140a5
audio: Only allocate fake_stream if we're using the standard audio threads.
src/audio/SDL_audio.c
--- a/src/audio/SDL_audio.c	Tue Aug 09 00:44:05 2016 -0400
+++ b/src/audio/SDL_audio.c	Tue Aug 09 00:44:59 2016 -0400
@@ -1149,7 +1149,6 @@
     SDL_AudioDevice *device;
     SDL_bool build_cvt;
     void *handle = NULL;
-    Uint32 stream_len;
     int i = 0;
 
     if (!SDL_WasInit(SDL_INIT_AUDIO)) {
@@ -1338,19 +1337,6 @@
         }
     }
 
-    /* Allocate a fake audio memory buffer */
-    stream_len = (device->convert.needed) ? device->convert.len_cvt : 0;
-    if (device->spec.size > stream_len) {
-        stream_len = device->spec.size;
-    }
-    SDL_assert(stream_len > 0);
-    device->fake_stream = (Uint8 *) SDL_malloc(stream_len);
-    if (device->fake_stream == NULL) {
-        close_audio_device(device);
-        SDL_OutOfMemory();
-        return 0;
-    }
-
     if (device->spec.callback == NULL) {  /* use buffer queueing? */
         /* pool a few packets to start. Enough for two callbacks. */
         const int packetlen = SDL_AUDIOBUFFERQUEUE_PACKETLEN;
@@ -1377,6 +1363,20 @@
     if (!current_audio.impl.ProvidesOwnCallbackThread) {
         /* Start the audio thread */
 
+        /* Allocate a fake audio buffer; only used by our internal threads. */
+        Uint32 stream_len = (device->convert.needed) ? device->convert.len_cvt : 0;
+        if (device->spec.size > stream_len) {
+            stream_len = device->spec.size;
+        }
+        SDL_assert(stream_len > 0);
+
+        device->fake_stream = (Uint8 *) SDL_malloc(stream_len);
+        if (device->fake_stream == NULL) {
+            close_audio_device(device);
+            SDL_OutOfMemory();
+            return 0;
+        }
+
         /* !!! FIXME: we don't force the audio thread stack size here because it calls into user code, but maybe we should? */
         /* buffer queueing callback only needs a few bytes, so make the stack tiny. */
         char name[64];