Skip to content

Crash: AVAudioUnit / AVAudioNode deallocated while CoreAudio still rendering (EXC_BAD_ACCESS in AUAudioUnitV2Bridge) #586

@aaravchour

Description

@aaravchour

Amperfy 2.0.0 is crashing during audio playback due to an audio unit being deallocated while CoreAudio is still using it. The crash consistently occurs inside objc_msgSend when AUAudioUnitV2Bridge.invalidateAudioUnit is called on a freed object.

Crash summary:

  • Exception: EXC_BAD_ACCESS (SIGSEGV)

  • Location: objc_msgSend → AUAudioUnitV2Bridge.invalidateAudioUnit

  • Thread: Background queue (source.queue)

  • Likely cause: An AVAudioUnit / AVAudioNode is being released on a non‑main queue while the audio engine is still rendering.

Key stack trace:

Thread 14 Crashed:
objc_msgSend
AUAudioUnitV2Bridge.invalidateAudioUnit
AUInterfaceBaseV3::~AUInterfaceBaseV3
AVAudioNodeImpl::~AVAudioNodeImpl
AVAudioUnitImpl::~AVAudioUnitImpl
-[AVAudioNode dealloc]
AmperfyKit …
Interpretation:

This appears to be a race condition:
AVAudioNode or AVAudioUnit is torn down while CoreAudio still holds references to it. The deallocation happens on a custom dispatch queue, not the main thread, which may violate AVAudioEngine’s threading expectations.

Suggested areas to investigate:

  • Ensure all AVAudioNode / AVAudioUnit teardown happens on the main thread.

  • Stop the engine (engine.stop()) before removing or releasing nodes.

  • Ensure no background queue is releasing audio objects while render callbacks are active.

  • Verify that input/output streams are closed before node destruction.

Environment:

  • macOS 26.3 (25D5087f)

  • Apple Silicon (ARM64)

  • Amperfy 2.0.0 (build 10)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions