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

Remove Send bound on handle returned from Editor::spawn #148

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions nih_plug_egui/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ where
&self,
parent: ParentWindowHandle,
context: Arc<dyn GuiContext>,
) -> Box<dyn std::any::Any + Send> {
) -> Box<dyn std::any::Any> {
let build = self.build.clone();
let update = self.update.clone();
let state = self.user_state.clone();
Expand Down Expand Up @@ -153,10 +153,6 @@ struct EguiEditorHandle {
window: WindowHandle,
}

/// The window handle enum stored within 'WindowHandle' contains raw pointers. Is there a way around
/// having this requirement?
unsafe impl Send for EguiEditorHandle {}

impl Drop for EguiEditorHandle {
fn drop(&mut self) {
self.egui_state.open.store(false, Ordering::Release);
Expand Down
6 changes: 1 addition & 5 deletions nih_plug_iced/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<E: IcedEditor> Editor for IcedEditorWrapper<E> {
&self,
parent: ParentWindowHandle,
context: Arc<dyn GuiContext>,
) -> Box<dyn std::any::Any + Send> {
) -> Box<dyn std::any::Any> {
let (unscaled_width, unscaled_height) = self.iced_state.size();
let scaling_factor = self.scaling_factor.load();

Expand Down Expand Up @@ -157,10 +157,6 @@ struct IcedEditorHandle<Message: 'static + Send> {
window: iced_baseview::WindowHandle<Message>,
}

/// The window handle enum stored within 'WindowHandle' contains raw pointers. Is there a way around
/// having this requirement?
unsafe impl<Message: Send> Send for IcedEditorHandle<Message> {}

impl<Message: Send> Drop for IcedEditorHandle<Message> {
fn drop(&mut self) {
self.iced_state.open.store(false, Ordering::Release);
Expand Down
6 changes: 1 addition & 5 deletions nih_plug_vizia/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Editor for ViziaEditor {
&self,
parent: ParentWindowHandle,
context: Arc<dyn GuiContext>,
) -> Box<dyn std::any::Any + Send> {
) -> Box<dyn std::any::Any> {
let app = self.app.clone();
let vizia_state = self.vizia_state.clone();
let theming = self.theming;
Expand Down Expand Up @@ -165,10 +165,6 @@ struct ViziaEditorHandle {
window: WindowHandle,
}

/// The window handle enum stored within 'WindowHandle' contains raw pointers. Is there a way around
/// having this requirement?
unsafe impl Send for ViziaEditorHandle {}

impl Drop for ViziaEditorHandle {
fn drop(&mut self) {
self.vizia_state.open.store(false, Ordering::Release);
Expand Down
2 changes: 1 addition & 1 deletion src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub trait Editor: Send {
&self,
parent: ParentWindowHandle,
context: Arc<dyn GuiContext>,
) -> Box<dyn Any + Send>;
) -> Box<dyn Any>;

/// Returns the (current) size of the editor in pixels as a `(width, height)` pair. This size
/// must be reported in _logical pixels_, i.e. the size before being multiplied by the DPI
Expand Down
5 changes: 4 additions & 1 deletion src/wrapper/clap/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub struct Wrapper<P: ClapPlugin> {
editor: AtomicRefCell<Option<Mutex<Box<dyn Editor>>>>,
/// A handle for the currently active editor instance. The plugin should implement `Drop` on
/// this handle for its closing behavior.
editor_handle: Mutex<Option<Box<dyn Any + Send>>>,
editor_handle: Mutex<Option<Box<dyn Any>>>,
/// The DPI scaling factor as passed to the [IPlugViewContentScaleSupport::set_scale_factor()]
/// function. Defaults to 1.0, and will be kept there on macOS. When reporting and handling size
/// the sizes communicated to and from the DAW should be scaled by this factor since NIH-plug's
Expand Down Expand Up @@ -258,6 +258,9 @@ pub struct Wrapper<P: ClapPlugin> {
background_thread: AtomicRefCell<Option<BackgroundThread<Task<P>, Self>>>,
}

unsafe impl<P: ClapPlugin> Send for Wrapper<P> {}
unsafe impl<P: ClapPlugin> Sync for Wrapper<P> {}

/// Tasks that can be sent from the plugin to be executed on the main thread in a non-blocking
/// realtime-safe way. Instead of using a random thread or the OS' event loop like in the Linux
/// implementation, this uses [`clap_host::request_callback()`] instead.
Expand Down
Loading