From e6c7cdc1baa07b64cb65fd81c1748c67dc99c3d2 Mon Sep 17 00:00:00 2001
From: Chris Robinson <chris.kcat@gmail.com>
Date: Tue, 9 Mar 2021 02:55:01 -0800
Subject: Initialize the new audio unit before disposing the old one

---
 alc/backends/coreaudio.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

(limited to 'alc/backends/coreaudio.cpp')

diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp
index 977bdc78..43c78063 100644
--- a/alc/backends/coreaudio.cpp
+++ b/alc/backends/coreaudio.cpp
@@ -123,6 +123,12 @@ void CoreAudioPlayback::open(const char *name)
     if(err != noErr)
         throw al::backend_exception{al::backend_error::NoDevice,
             "Could not create component instance: %u", err};
+
+    err = AudioUnitInitialize(audioUnit);
+    if(err != noErr)
+        throw al::backend_exception{al::backend_error::DeviceError,
+            "Could not initialize audio unit: %u", err};
+
     /* WARNING: I don't know if "valid" audio unit values are guaranteed to be
      * non-0. If not, this logic is broken.
      */
@@ -133,12 +139,6 @@ void CoreAudioPlayback::open(const char *name)
     }
     mAudioUnit = audioUnit;
 
-    /* init and start the default audio unit... */
-    err = AudioUnitInitialize(mAudioUnit);
-    if(err != noErr)
-        throw al::backend_exception{al::backend_error::DeviceError,
-            "Could not initialize audio unit: %u", err};
-
     mDevice->DeviceName = name;
 }
 
-- 
cgit v1.2.3