From 216dba23cb5d1ec176389e574c7be0aaf0edb869 Mon Sep 17 00:00:00 2001 From: Ben Frankel Date: Sun, 4 Aug 2024 16:34:51 +0300 Subject: [PATCH] Explicitly order `CameraUpdateSystem` before `UiSystem::Prepare` (#14609) Fixes https://github.com/bevyengine/bevy/issues/14277. May also fix https://github.com/bevyengine/bevy/issues/14255, needs verification. Explicitly order `CameraUpdateSystem` before `UiSystem::Prepare`, so that when the window resizes, `camera_system` will update the `Camera`'s viewport size before `ui_layout_system` also reacts to the window resize and tries to read the new `Camera` viewport size to set UI node sizes accordingly. I tested that explicitly ordering `CameraUpdateSystem` _after_ triggers the buggy behavior, and explicitly ordering it _before_ does not trigger the buggy behavior or crash the app (which also demonstrates that the system sets are ambiguous). --- `CameraUpdateSystem` is now explicitly ordered before `UiSystem::Prepare` instead of being ambiguous with it. --- crates/bevy_ui/src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index 0688510432..8e7e11879b 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -54,6 +54,7 @@ use bevy_app::prelude::*; use bevy_ecs::prelude::*; use bevy_input::InputSystem; use bevy_render::{ + camera::CameraUpdateSystem, view::{check_visibility, VisibilitySystems}, RenderApp, }; @@ -129,6 +130,16 @@ impl Plugin for UiPlugin { .register_type::() .register_type::() .register_type::() + .configure_sets( + PostUpdate, + ( + CameraUpdateSystem, + UiSystem::Stack, + UiSystem::Layout, + UiSystem::Outlines, + ) + .chain(), + ) .add_systems( PreUpdate, ui_focus_system.in_set(UiSystem::Focus).after(InputSystem), @@ -205,11 +216,6 @@ fn build_text_interop(app: &mut App) { widget::measure_text_system .before(UiSystem::Layout) // Potential conflict: `Assets` - // In practice, they run independently since `bevy_render::camera_update_system` - // will only ever observe its own render target, and `widget::measure_text_system` - // will never modify a pre-existing `Image` asset. - .ambiguous_with(bevy_render::camera::CameraUpdateSystem) - // Potential conflict: `Assets` // Since both systems will only ever insert new [`Image`] assets, // they will never observe each other's effects. .ambiguous_with(bevy_text::update_text2d_layout)