bevy/crates/bevy_ui/src
robtfm 30940e5cb4
fix occasional crash moving ui root nodes (#11371)
# Objective

fix an occasional crash when moving ui root nodes between cameras.

occasionally, updating the TargetCamera of a ui element and then
removing the element causes a crash.

i believe that is because when we assign a child in taffy, the old
parent doesn't remove that child from it's children, so we have:

```
user: create root node N1, camera A
-> layout::set_camera_children(A) : 
	- create implicit node A1
	- assign 1 as child -> taffy.children[A1] = [N1], taffy.parents[1] = A1

user: move root node N1 to camera B
-> layout::set_camera_children(B) :
	- create implicit node B1
	- assign 1 as child -> taffy.children[A1] = [N1], taffy.children[B1] = [N1], taffy.parents[1] = B1
-> layout::set_camera_children(A) :
	- remove implicit node A1 (which still has N1 as a child) -> 
		-> taffy sets parent[N1] = None ***
		-> taffy.children[B1] = [N1], taffy.parents[1] = None

user: remove N1
-> layout::remove_entities(N1)
	- since parent[N1] is None, it's not removed from B1 -> taffy.children[B1] = [N1], taffy.parents[1] is removed
-> layout::set_camera_children(B)
	- remove implicit node B1
	- taffy crash accessing taffy.parents[N1]
```

## Solution

we can work around this by making sure to remove the child from the old
parent if one exists (this pr).

i think a better fix may be for taffy to check in `Taffy::remove` and
only set the child's parent to None if it is currently equal to the node
being removed but i'm not sure if there's an explicit assumption we're
violating here (@nicoburns).
2024-01-17 16:53:27 +00:00
..
layout fix occasional crash moving ui root nodes (#11371) 2024-01-17 16:53:27 +00:00
render Texture Atlas rework (#5103) 2024-01-16 13:59:08 +00:00
widget Texture Atlas rework (#5103) 2024-01-16 13:59:08 +00:00
accessibility.rs resolve all internal ambiguities (#10411) 2024-01-09 19:08:15 +00:00
focus.rs Camera-driven UI (#10559) 2024-01-16 00:39:10 +00:00
geometry.rs Made the remaining types from bevy_ui to reflect the Default trait if… (#11199) 2024-01-03 18:57:05 +00:00
lib.rs Texture Atlas rework (#5103) 2024-01-16 13:59:08 +00:00
measurement.rs Change the default for the measure_func field of ContentSize to None. (#9346) 2023-08-07 23:06:40 +00:00
node_bundles.rs Texture Atlas rework (#5103) 2024-01-16 13:59:08 +00:00
stack.rs Remove unnecessary parentheses (#10990) 2023-12-16 02:26:18 +00:00
ui_material.rs Provide GlobalsUniform in UiMaterial shaders (#10739) 2023-11-28 12:08:28 +00:00
ui_node.rs Texture Atlas rework (#5103) 2024-01-16 13:59:08 +00:00
update.rs Camera-driven UI (#10559) 2024-01-16 00:39:10 +00:00