From 7f09720ab2dc1ee373c3bb9d9a532b0fe93ecf49 Mon Sep 17 00:00:00 2001 From: shuo Date: Tue, 6 Sep 2022 15:06:17 +0000 Subject: [PATCH] disable window pre creation for ios (#5883) # Objective Fixes #5882 ## Solution Per https://github.com/rust-windowing/winit/issues/1705, the root cause is "UIWindow should be created inside UIApplicationMain". Currently, there are two places to create UIWindow, one is Plugin's build function, which is not inside UIApplicationMain. Just comment it out, and it works. --- crates/bevy_winit/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 4ca444b37fbcc3..66804c5a426b42 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -48,13 +48,15 @@ impl Plugin for WinitPlugin { #[cfg(target_arch = "wasm32")] app.add_plugin(web_resize::CanvasParentResizePlugin); let event_loop = EventLoop::new(); - #[cfg(not(target_os = "android"))] + #[cfg(not(any(target_os = "android", target_os = "ios", target_os = "macos")))] let mut create_window_reader = WinitCreateWindowReader::default(); - #[cfg(target_os = "android")] + #[cfg(any(target_os = "android", target_os = "ios", target_os = "macos"))] let create_window_reader = WinitCreateWindowReader::default(); // Note that we create a window here "early" because WASM/WebGL requires the window to exist prior to initializing // the renderer. - #[cfg(not(target_os = "android"))] + // And for ios and macos, we should not create window early, all ui related code should be executed inside + // UIApplicationMain/NSApplicationMain. + #[cfg(not(any(target_os = "android", target_os = "ios", target_os = "macos")))] handle_create_window_events(&mut app.world, &event_loop, &mut create_window_reader.0); app.insert_resource(create_window_reader) .insert_non_send_resource(event_loop);