From cebfa0b2661cfca4fbf5ae054dad0c6199c5f141 Mon Sep 17 00:00:00 2001 From: Junfeng Liu Date: Fri, 16 Oct 2020 04:31:34 +0800 Subject: [PATCH] Expose a pointer of EventLoopProxy to process custom messages (#674) --- crates/bevy_winit/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index fc43772be98418..fd1a3626c9a797 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -22,6 +22,9 @@ use winit::{ #[derive(Default)] pub struct WinitPlugin; +#[derive(Debug)] +pub struct EventLoopProxyPtr(pub usize); + impl Plugin for WinitPlugin { fn build(&self, app: &mut AppBuilder) { app @@ -134,6 +137,11 @@ pub fn winit_runner(mut app: App) { let mut create_window_event_reader = EventReader::::default(); let mut app_exit_event_reader = EventReader::::default(); + app.resources + .insert_thread_local(EventLoopProxyPtr( + Box::into_raw(Box::new(event_loop.create_proxy())) as usize, + )); + handle_create_window_events( &mut app.resources, &event_loop,