Skip to content

Commit d5595c9

Browse files
Switch to try_insert in UICameraPropagate (#21519)
# Objective I've been having panics in situations where: - I despawn a UI Root Node in PostUpdate - I don't have any system order dependency between my PostUpdate system and `UiSystems::Prepare`, so there was no sync point between the two Therefore the order of operations was: - My system runs and queues a command to despawn a root node - The UI system runs and tries to insert `Propagate` on my root node - CommandExecutions: - my command to despawn the root node is executed - the command to insert Propagate is executed, causing a panics This means that any attempt to despawn a Root node in PostUpdate will probably cause these kinds of panics. ## Solution Replace the command with `try_insert` so that if the Root Node is despawned we don't try to add a Propagate component on it. ## Testing This fixed the issue in my repo
1 parent ea8f22e commit d5595c9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

crates/bevy_ui/src/update.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub fn propagate_ui_target_cameras(
153153

154154
commands
155155
.entity(root_entity)
156-
.insert(Propagate(ComputedUiTargetCamera { camera }));
156+
.try_insert(Propagate(ComputedUiTargetCamera { camera }));
157157

158158
let (scale_factor, physical_size) = camera_query
159159
.get(camera)
@@ -168,7 +168,7 @@ pub fn propagate_ui_target_cameras(
168168

169169
commands
170170
.entity(root_entity)
171-
.insert(Propagate(ComputedUiRenderTargetInfo {
171+
.try_insert(Propagate(ComputedUiRenderTargetInfo {
172172
scale_factor,
173173
physical_size,
174174
}));

0 commit comments

Comments
 (0)