diff --git a/src/event_loop/linux.rs b/src/event_loop/linux.rs index 543308dd..6bf456a0 100644 --- a/src/event_loop/linux.rs +++ b/src/event_loop/linux.rs @@ -8,6 +8,7 @@ use std::thread::{self, JoinHandle, ThreadId}; use super::{EventLoop, MainThreadExecutor}; use crate::nih_log; +use crate::util::permit_alloc; /// See [`EventLoop`][super::EventLoop]. #[cfg_attr( @@ -83,7 +84,9 @@ where } fn is_main_thread(&self) -> bool { - thread::current().id() == self.main_thread_id + // FIXME: `thread::current()` may allocate the first time it's called, is there a safe + // nonallocating version of this without using huge OS-specific libraries? + permit_alloc(|| thread::current().id() == self.main_thread_id) } } diff --git a/src/event_loop/windows.rs b/src/event_loop/windows.rs index 0d9c450a..e17163d2 100644 --- a/src/event_loop/windows.rs +++ b/src/event_loop/windows.rs @@ -20,6 +20,7 @@ use windows::Win32::UI::WindowsAndMessaging::{ use super::{EventLoop, MainThreadExecutor}; use crate::nih_log; +use crate::util::permit_alloc; /// The custom message ID for our notify event. If the hidden event loop window receives this, then /// it knows it should start polling events. @@ -160,7 +161,9 @@ where } fn is_main_thread(&self) -> bool { - thread::current().id() == self.main_thread_id + // FIXME: `thread::current()` may allocate the first time it's called, is there a safe + // nonallocating version of this without using huge OS-specific libraries? + permit_alloc(|| thread::current().id() == self.main_thread_id) } } diff --git a/src/wrapper/clap/wrapper.rs b/src/wrapper/clap/wrapper.rs index 22b513dd..c7c93034 100644 --- a/src/wrapper/clap/wrapper.rs +++ b/src/wrapper/clap/wrapper.rs @@ -66,6 +66,7 @@ use crate::param::internals::ParamPtr; use crate::plugin::{ BufferConfig, BusConfig, ClapPlugin, Editor, NoteEvent, ParentWindowHandle, ProcessStatus, }; +use crate::util::permit_alloc; use crate::wrapper::state; use crate::wrapper::util::{hash_param_id, process_wrapper, strlcpy}; @@ -255,7 +256,9 @@ impl EventLoop> for Wrapper

{ // check if this is the same thread as the one that created the plugin instance. match &*self.host_thread_check.borrow() { Some(thread_check) => unsafe { (thread_check.is_main_thread)(&*self.host_callback) }, - None => thread::current().id() == self.main_thread_id, + // FIXME: `thread::current()` may allocate the first time it's called, is there a safe + // nonallocating version of this without using huge OS-specific libraries? + None => permit_alloc(|| thread::current().id() == self.main_thread_id), } } }