From ce8dfa5a67d0ad2f5c3397f39e540fc2ce2dc4a2 Mon Sep 17 00:00:00 2001 From: Chrizz Gelbach Date: Mon, 19 Oct 2026 15:14:39 +0200 Subject: [PATCH] Stop the audio hardware before freeing the render buffers in deinit The IO thread keeps pulling from the render callback until the hardware is stopped. Releasing an AudioPlayer while it was still rendering (e.g. after an error, where pause() is a no-op) freed inOutAudioBufferList while the render block still used it and crashed in AVAudioEngineGraph::RenderToABL. Stop the hardware first, then the engine, so the IO thread does not call the manual rendering block of a stopped engine. --- AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift b/AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift index 13fba34..a17d0d0 100644 --- a/AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift +++ b/AudioStreaming/Streaming/AudioPlayer/AudioPlayer.swift @@ -225,6 +225,10 @@ open class AudioPlayer { } deinit { + // The IO thread keeps pulling from the render callback until the hardware is stopped, + // so stop it before the buffers it renders into are freed. + player.auAudioUnit.stopHardware() + audioEngine.stop() playerContext.audioPlayingEntry?.close() clearQueue() rendererContext.clean()