Skip to content

Commit

Permalink
fix panic: invalid SlotMap key used (#13990)
Browse files Browse the repository at this point in the history
# Objective

Tight, in-frame generation, re-parenting, despawning, etc., UI
operations could sometime lead taffy to panic (invalid SlotMap key used)
when an entity with an invalid state later despawned.

Fixes #12403 

## Solution

Move the `remove_entities` call after children updates.

## Testing

`sickle_ui` had a case that always caused the panic. Tested before this
change, after this change, and before the change again to make sure the
error is there without the fix. The fix worked. Test steps and used
commit described in issue #12403.

I have also ran every bevy UI example, though none of them deal with
entity re-parenting or removal. No regression detected on them.

Tested on Windows only.
  • Loading branch information
eidloi authored and mockersf committed Jun 25, 2024
1 parent a41ed78 commit a0e7429
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crates/bevy_ui/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ pub fn ui_layout_system(
}
scale_factor_events.clear();

// clean up removed nodes
ui_surface.remove_entities(removed_components.removed_nodes.read());

// clean up removed cameras
ui_surface.remove_camera_entities(removed_components.removed_cameras.read());

Expand All @@ -217,6 +214,9 @@ pub fn ui_layout_system(
}
}

// clean up removed nodes after syncing children to avoid potential panic (invalid SlotMap key used)
ui_surface.remove_entities(removed_components.removed_nodes.read());

for (camera_id, camera) in &camera_layout_info {
let inverse_target_scale_factor = camera.scale_factor.recip();

Expand Down

0 comments on commit a0e7429

Please sign in to comment.