From a0a9f79592de456b7b7fa9a3401470f42a3dbd80 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Tue, 24 Jun 2025 05:00:46 -0700 Subject: [PATCH] HRTF: Fix deadlock with restarting motion tracking Motion tracking was storing a strong reference to the HRTF DSP node, which was resulting in the DSP not shutting down or restarting properly, leading to playback hanging. Signed-off-by: Christopher Snowhill --- Audio/Chain/DSP/DSPHRTFNode.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Audio/Chain/DSP/DSPHRTFNode.m b/Audio/Chain/DSP/DSPHRTFNode.m index 26e50e0d7..59eb89d24 100644 --- a/Audio/Chain/DSP/DSPHRTFNode.m +++ b/Audio/Chain/DSP/DSPHRTFNode.m @@ -40,7 +40,7 @@ static simd_float4x4 convertMatrix(CMRotationMatrix r) { static NSLock *motionManagerLock = nil; API_AVAILABLE(macos(14.0)) static CMHeadphoneMotionManager *motionManager = nil; -static DSPHRTFNode *registeredMotionListener = nil; +static DSPHRTFNode __weak *registeredMotionListener = nil; #endif static void registerMotionListener(DSPHRTFNode *listener) { @@ -55,7 +55,8 @@ static void registerMotionListener(DSPHRTFNode *listener) { [motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMDeviceMotion * _Nullable motion, NSError * _Nullable error) { if(motion) { [motionManagerLock lock]; - [registeredMotionListener reportMotion:convertMatrix(motion.attitude.rotationMatrix)]; + if(registeredMotionListener) + [registeredMotionListener reportMotion:convertMatrix(motion.attitude.rotationMatrix)]; [motionManagerLock unlock]; } }];