-
-
Notifications
You must be signed in to change notification settings - Fork 212
Open
Description
I'm trying to write a plugin that may change latency on the fly. However, I've found that when changing the latency, it might crash the plugin when using the CLAP version.
Here's a recording of me causing a crash by change the latency a bunch (with a debugger attached):
Code_Wiz7EV7vaP.mp4
The crash seems to start from the CLAP wrapper's activate function, this part:
// This preallocates enough space so we can transform all of the host's raw channel
// pointers into a set of `Buffer` objects for the plugin's main and auxiliary IO
*wrapper.buffer_manager.borrow_mut() =
BufferManager::for_audio_io_layout(max_frames_count as usize, audio_io_layout);Trying to borrow the buffer manager causes this error:
13:02:38 [ERROR] nih_plug::wrapper::util: thread 'unnamed' panicked at 'already mutably borrowed': C:\Users\James\.cargo\registry\src\index.crates.io-6f17d22bba15001f\atomic_refcell-0.1.13\src\lib.rs:155
The code I used to change latency is the following:
// self.latency_changed is a `Arc<AtomicBool, Global>`
// code from Diopser example plugin
let latency_changed = self
.latency_changed
.compare_exchange(true, false, Ordering::Acquire, Ordering::Relaxed)
.is_ok();
if latency_changed {
let lookahead_samples =
self.params.lookahead.value() / 1000.0 * ctx.transport().sample_rate;
nih_log!("Changing latency samples to:");
nih_dbg!(lookahead_samples.round() as u32);
// update latency for daw, is no-op if value is same
ctx.set_latency_samples(lookahead_samples.round() as u32);
}That code is run in the process() loop
Metadata
Metadata
Assignees
Labels
No labels