Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLAP wrapper can randomly crash when changing latency #177

Open
jamesWalker55 opened this issue Nov 30, 2024 · 0 comments
Open

CLAP wrapper can randomly crash when changing latency #177

jamesWalker55 opened this issue Nov 30, 2024 · 0 comments

Comments

@jamesWalker55
Copy link

jamesWalker55 commented Nov 30, 2024

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

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

No branches or pull requests

1 participant