Fix realtime buffer-growth violation in audio callback - #117
Merged
Conversation
…callback scratch_multi was resize()'d on the audio thread every block for multi-out bridged inserts; capacity is now pre-reserved on the control thread in resolve_bridge_sinks so the audio-thread resize never reallocates, while preserving the exact .len() invariant scatter_vsti_output_children depends on. Also removes redundant pre-zero loops in the cpal, WASAPI exclusive, and WDM-KS output callbacks — fill_output_f32 already overwrites every sample on every reachable path — and clamps rather than grows a defensively-sized scratch buffer in the WASAPI exclusive path. Includes an unrelated one-line fix (missing <dlfcn.h> include) that was blocking the crate from building on Linux at all.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scratch_multiwasresize()'d on the audio thread every block for multi-out bridged plugin inserts — a real-time-safety violation (buffer growth in the audio callback). Fixed by pre-reserving its capacity on the control thread inresolve_bridge_sinks, so the audio-threadresizenever reallocates, while keeping the exact.len()invariantscatter_vsti_output_childrendepends on to recover the channel stride.fill_output_f32already overwrites every sample of its output slice on every reachable path, so the pre-zero was dead work every block.vst2_processor.cppwas missing#include <dlfcn.h>, which broke the whole crate's build on Linux (pre-existing onmain, unrelated to the buffer work — included only because it blocked verifying everything else).Test plan
cargo test -p sphere_directaudioengine --lib— 236 passed, includingvsti_output_children_scatter_demuxes_channel_pairs(the test that depends on thescratch_multi.len()invariant)cargo check --workspace— cleancargo fmt -p sphere_directaudioengine -- --check— cleanwasapi_exclusive.rs/wdm_ks.rsare Windows-only and could not be compile-checked or runtime-tested on this Linux machine — needs a Windows build/runtime check before merge