Hi there,
I’m currently working on a plugin for another program. The program and the plugin interact through FFI with C. Therefore, the plugin does not have a traditional entry point like a main function. Instead, the program calls a function to initialize the plugin and another function to shut down the plugin. I would like to use Iced for my plugin in places where a GUI needed. However, for this to work Iced must not block the main thread. Otherwise the program cannot start until the GUI of the plugin is closed.
I tried to run the iced application on a separate thread but it causes the thread to panic with the following error:
Initializing the event loop outside of the main thread is a significant cross-platform compatibility hazard. If you absolutely need to create an EventLoop on a different thread, you can use the
EventLoopBuilderExtUnix::any_thread
function.
Is there a simple solution to this? I don’t have much experience with GUI/frontend programming, so I don’t know much about winit or wgpu.
My code looks something like this:
static mut MAIN_GUI_JOIN_HANDLE: OnceCell<JoinHandle<iced::Result>> = OnceCell::new();
// GUI entry point
pub fn start_gui() {
let join_handle = thread::spawn(||
PluginApplication::run(Settings::default())
);
unsafe { MAIN_GUI_JOIN_HANDLE.set(join_handle).unwrap(); }
}