fix(coreaudio): crashes from early initialization#1184
Conversation
Configuring the stream after the AudioUnit is initialized breaks the CoreAudio contract and causes crashes on certain drivers.
There was a problem hiding this comment.
Pull request overview
Defers CoreAudio AudioUnit initialization until after stream properties/callbacks are configured, avoiding CoreAudio contract violations that can trigger driver crashes (fixes #1182).
Changes:
- macOS: ensure newly created
AudioUnits are uninitialized during configuration and only initialized immediately before stream start. - macOS: query device buffer frame size range via
AudioObjectGetPropertyData(device-level) to avoid instantiating/initializing anAudioUnitduring device introspection. - iOS: align RemoteIO setup to configure recording + stream format first, then initialize the
AudioUnit.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/host/coreaudio/macos/device.rs |
Avoids early AudioUnit initialization and removes AudioUnit dependency from buffer size range queries; initializes only right before starting streams. |
src/host/coreaudio/ios/mod.rs |
Moves initialization to the end of setup_stream_audio_unit after configuration (including recording mode + stream format). |
CHANGELOG.md |
Documents the CoreAudio crash fix related to early initialization. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I think the changes here would already solve the problem when using the |
|
Sure, if it’ll be released soon then we can wait for that. I’d like to include it in cpal v0.18. Besides the coreaudio-rs PR, to verify my understanding, does my PR fix it for you completely? |
Sorry. I got distracted earlier (I'm a new father and very tired) and forgot to push the merge button. coreaudio-rs 0.14.2 is published.. |
|
I tested the PR right now, and I still could reproduce a crash due to the early initialization inside coreaudio-rs when starting an output stream. Since that's not yet avoided here, it makes sense that it still happens. But given the new coreaudio-rs version is already available, it would be straight-forward to integrate that in here, right? Additionally, there's a function called |
|
Thanks. I’ll update soon. |
|
Hope this does it - feedback appreciated as I can't reproduce it locally. |
|
I'm going to merge this and close #1182. Please re-open that ticket if there are remaining issues. |
|
Ok, I'll have access to my test setup in a couple of days, so I'll notify if I manage to reproduce the crashes again. |
Configuring the stream after the
AudioUnitis initialized breaks the CoreAudio contract and caused crashes on certain drivers.Fixes #1182