From 05866e3fa70b42f90738d26f6ecce1c7f9aac496 Mon Sep 17 00:00:00 2001 From: Junfeng Liu Date: Tue, 13 Oct 2020 11:00:56 +0800 Subject: [PATCH] Expose a pointer of EventLoopProxy to process custom messages --- 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 f95544cdcd949..20a482a278248 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 @@ -81,6 +84,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,