From 255bb29f2db3d52c5173378e2a9599ae6a3de4d2 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Tue, 29 Apr 2025 16:22:32 +0100 Subject: [PATCH] Renamed `get_ui_graph` to `new_ui_graph`. Call `new_ui_graph` only after we've successfully retrieved the relevant subgraphs. --- crates/bevy_ui/src/render/mod.rs | 42 +++++++++++++++++--------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 8cb61cde21..3e6c34c188 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -164,32 +164,34 @@ pub fn build_ui_render(app: &mut App) { ); // Render graph - let ui_graph_2d = get_ui_graph(render_app); - let ui_graph_3d = get_ui_graph(render_app); - let mut graph = render_app.world_mut().resource_mut::(); + render_app + .world_mut() + .resource_scope(|world, mut graph: Mut| { + if let Some(graph_2d) = graph.get_sub_graph_mut(Core2d) { + let ui_graph_2d = new_ui_graph(world); + graph_2d.add_sub_graph(SubGraphUi, ui_graph_2d); + graph_2d.add_node(NodeUi::UiPass, RunUiSubgraphOnUiViewNode); + graph_2d.add_node_edge(Node2d::EndMainPass, NodeUi::UiPass); + graph_2d.add_node_edge(Node2d::EndMainPassPostProcessing, NodeUi::UiPass); + graph_2d.add_node_edge(NodeUi::UiPass, Node2d::Upscaling); + } - if let Some(graph_2d) = graph.get_sub_graph_mut(Core2d) { - graph_2d.add_sub_graph(SubGraphUi, ui_graph_2d); - graph_2d.add_node(NodeUi::UiPass, RunUiSubgraphOnUiViewNode); - graph_2d.add_node_edge(Node2d::EndMainPass, NodeUi::UiPass); - graph_2d.add_node_edge(Node2d::EndMainPassPostProcessing, NodeUi::UiPass); - graph_2d.add_node_edge(NodeUi::UiPass, Node2d::Upscaling); - } - - if let Some(graph_3d) = graph.get_sub_graph_mut(Core3d) { - graph_3d.add_sub_graph(SubGraphUi, ui_graph_3d); - graph_3d.add_node(NodeUi::UiPass, RunUiSubgraphOnUiViewNode); - graph_3d.add_node_edge(Node3d::EndMainPass, NodeUi::UiPass); - graph_3d.add_node_edge(Node3d::EndMainPassPostProcessing, NodeUi::UiPass); - graph_3d.add_node_edge(NodeUi::UiPass, Node3d::Upscaling); - } + if let Some(graph_3d) = graph.get_sub_graph_mut(Core3d) { + let ui_graph_3d = new_ui_graph(world); + graph_3d.add_sub_graph(SubGraphUi, ui_graph_3d); + graph_3d.add_node(NodeUi::UiPass, RunUiSubgraphOnUiViewNode); + graph_3d.add_node_edge(Node3d::EndMainPass, NodeUi::UiPass); + graph_3d.add_node_edge(Node3d::EndMainPassPostProcessing, NodeUi::UiPass); + graph_3d.add_node_edge(NodeUi::UiPass, Node3d::Upscaling); + } + }); app.add_plugins(UiTextureSlicerPlugin); app.add_plugins(BoxShadowPlugin); } -fn get_ui_graph(render_app: &mut SubApp) -> RenderGraph { - let ui_pass_node = UiPassNode::new(render_app.world_mut()); +fn new_ui_graph(world: &mut World) -> RenderGraph { + let ui_pass_node = UiPassNode::new(world); let mut ui_graph = RenderGraph::default(); ui_graph.add_node(NodeUi::UiPass, ui_pass_node); ui_graph