Skip to content

Commit

Permalink
don't run create_surfaces system if not needed (#11720)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
mockersf committed Feb 5, 2024
1 parent 312df3c commit e927756
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions crates/bevy_render/src/view/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ impl Plugin for WindowRenderPlugin {
.init_resource::<ExtractedWindows>()
.init_resource::<WindowSurfaces>()
.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));
}
}

Expand Down Expand Up @@ -419,6 +424,18 @@ pub fn prepare_windows(
}
}

pub fn need_new_surfaces(
windows: Res<ExtractedWindows>,
window_surfaces: Res<WindowSurfaces>,
) -> 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,
Expand Down

0 comments on commit e927756

Please sign in to comment.