Skip to content

AUv2 stability and thread safety - #536

Open
CrushedPixel wants to merge 5 commits into
free-audio:nextfrom
SweetBiz:au-fixes
Open

AUv2 stability and thread safety#536
CrushedPixel wants to merge 5 commits into
free-audio:nextfrom
SweetBiz:au-fixes

Conversation

@CrushedPixel

Copy link
Copy Markdown

This PR addresses 4 issues I discovered while working on a plugin that serves as an offline audio generator.
If you would like me to split this into several PRs, please let me know.

These commits were made with the help of GPT-6 Astra and manually vetted and adjusted.

3780585
First of all, my plugin was not outputting any audio in Logic despite producing samples.
As I mentioned, my plugin generates audio offline and can play it back on user demand, even when there is no incoming audio. The fix was to clear the "silent" flag from the output when it's set for the input.

121fe78
My plugin was erroring during the CLAP activate callback and returned false, but clap-wrapper reported it as fine to Logic. This commit properly respects the return value of activate and start_processing.

0aedc9c
Logic activates my plugin on a worker thread, while clap-wrapper can call on_main_thread or access the editor on the main thread. These calls could overlap and access the same plugin state at the same time. AlwaysMainThread() only changes the result returned by the thread check, it doesn't prevent this overlap. This commit adds a shared lock so these calls happen one at a time. If the plugin is busy, the idle callback is deferred to the next tick.

a1ac38b
During cleanup, clap-wrapper called gui.destroy twice: once through the editor’s cleanup callback and then again directly.

Allow initialized rendering with nonzero host action flags. Give each
input pull its own flags and clear OutputIsSilence after CLAP processing,
so a silent track input cannot mark Swell's preview output as silent.
Check activate and start_processing before publishing render readiness.
Return an initialization failure when either is rejected, release the
adapter, and stop or deactivate only stages that actually succeeded.

This prevents a failed processor from appearing initialized to Logic and
allows a subsequent initialization attempt to start cleanly.
Logic may initialize on a worker while the idle timer and Cocoa editor
run on the main thread. Share the AU SDK entry mutex with those paths so
they cannot access plugin main-thread state concurrently. Idle skips a
busy tick without consuming pending requests or blocking the UI thread.

Start idle after port setup and keep the shared mutex alive through view
teardown. Editor callbacks run under their caller's entry guard.
The UI connection's destroy callback already calls gui.destroy and clears
the editor state. Remove the second gui.destroy call from Cleanup.
@CrushedPixel
CrushedPixel changed the base branch from main to next September 8, 2026 22:39
Comment thread src/wrapasauv2.cpp
Comment thread src/detail/auv2/auv2_shared.h
@defiantnerd

Copy link
Copy Markdown
Collaborator

Thanks for the contribution - please run clang-format on your patches, so it can be merged.

@CrushedPixel

Copy link
Copy Markdown
Author

Done!

@defiantnerd

Copy link
Copy Markdown
Collaborator

there are conflicts :(

@baconpaul

Copy link
Copy Markdown
Collaborator

ahh and we don't have write access to resolve them to your branch. Let us know if you can or if we need to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants