From e927756d724ce6c50c7aa47d8dfa180f587b6187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Mon, 5 Feb 2024 22:33:46 +0100 Subject: [PATCH] don't run `create_surfaces` system if not needed (#11720) # Objective - Change set of systems as I made a mistake in #11672 - Don't block main when not needed - Fixes #11235 ## Solution - add a run condition so that the system won't run and block main if not needed --- crates/bevy_render/src/view/window/mod.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/view/window/mod.rs b/crates/bevy_render/src/view/window/mod.rs index d10e354a17316..4c324c21933ee 100644 --- a/crates/bevy_render/src/view/window/mod.rs +++ b/crates/bevy_render/src/view/window/mod.rs @@ -43,8 +43,13 @@ impl Plugin for WindowRenderPlugin { .init_resource::() .init_resource::() .add_systems(ExtractSchedule, extract_windows) - .add_systems(Render, prepare_windows.in_set(RenderSet::PrepareAssets)) - .add_systems(Render, create_surfaces.in_set(RenderSet::ManageViews)); + .add_systems( + Render, + create_surfaces + .run_if(need_new_surfaces) + .in_set(RenderSet::PrepareAssets), + ) + .add_systems(Render, prepare_windows.in_set(RenderSet::ManageViews)); } } @@ -419,6 +424,18 @@ pub fn prepare_windows( } } +pub fn need_new_surfaces( + windows: Res, + window_surfaces: Res, +) -> bool { + for window in windows.windows.values() { + if !window_surfaces.configured_windows.contains(&window.entity) { + return true; + } + } + false +} + /// Creates window surfaces. pub fn create_surfaces( // By accessing a NonSend resource, we tell the scheduler to put this system on the main thread,