audio_waveforms icon indicating copy to clipboard operation
audio_waveforms copied to clipboard

fix: 🐛 Prevent `nullptr == Tap()` crash on iOS during recorder stream start

Open lavigarg-simform opened this issue 5 months ago • 0 comments

Description

On iOS, starting the recorder bytes stream could crash with a fatal nullptr == Tap() exception (issue #487).

RecorderBytesStreamEngine.attach() installed a tap on input bus 0 without clearing any existing tap first. Two paths left a stale tap on the bus:

  1. A second attach() call before detach() (re-start without teardown).
  2. A prior audioEngine.start() that threw — the tap was installed but never removed, leaking it onto the bus.

AVAudioEngine throws nullptr == Tap() when a tap is installed on a bus that already has one, crashing the app.

This PR makes attach() reset prior state before installing:

  • Stops the engine if running, removes any existing tap on bus 0, and resets totalFrames.
  • On a failed audioEngine.start(), removes the just-installed tap so it doesn't leak onto the bus and crash the next attach().

No public API change.

Checklist

  • [x] The title of my PR starts with a Conventional Commit prefix (fix:, feat:, docs: etc).
  • [x] I have followed the Contributor Guide when preparing my PR.
  • [ ] I have updated/added tests for ALL new/updated/fixed functionality.
  • [ ] I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • [ ] I have updated/added relevant examples in examples or docs.

Breaking Change?

  • [ ] Yes, this PR is a breaking change.
  • [x] No, this PR is not a breaking change.

Related Issues

Closes #487

lavigarg-simform avatar Jun 19 '26 14:06 lavigarg-simform