-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash in bevy_ui with specific node hierarchy #16765
Comments
No, it is not fixed by this PR, it still crashes with the same error. It actually is different, because in that issue the problem is with parent not being removed from child when manipulating hierarchy (or something like that). While in my case it calculates some value during layout and then assert fails. |
I've done some debugging: my test code// put it in examples folder in taffy
mod common {
pub mod image;
pub mod text;
}
use common::{
image::ImageContext,
text::{TextContext, WritingMode},
};
use taffy::prelude::*;
enum NodeContext {
Text(TextContext),
Image(ImageContext),
}
fn main() -> Result<(), taffy::TaffyError> {
let mut taffy: TaffyTree<NodeContext> = TaffyTree::new();
/*
1<div width=184 height=288 align_self=center justify_self=center>
2 <div>
3 <div position=absolute width=100% height=100% flex_direction=column>
4 <div margin_left=10 margin_right=10>
5 <text text="hello world"/>
</div>
</div>
</div>
</div>
*/
let node1 = taffy.new_leaf(Style {
size: Size { width: Dimension::Length(184.0), height: Dimension::Length(288.0) },
align_self: Some(AlignSelf::Center),
justify_self: Some(JustifySelf::Center),
..Default::default()
})?;
let node2 = taffy.new_leaf(Style { ..Default::default() })?;
taffy.add_child(node1, node2)?;
let node3 = taffy.new_leaf(Style {
position: Position::Absolute,
size: Size { width: Dimension::Percent(1.0), height: Dimension::Percent(1.0) },
flex_direction: FlexDirection::Column,
..Default::default()
})?;
taffy.add_child(node2, node3)?;
let node4 = taffy.new_leaf(Style {
margin: Rect {
left: LengthPercentageAuto::Length(10.0),
right: LengthPercentageAuto::Length(10.0),
top: LengthPercentageAuto::Auto,
bottom: LengthPercentageAuto::Auto,
},
..Default::default()
})?;
taffy.add_child(node3, node4)?;
let text = taffy.new_leaf_with_context(
Style::default(),
NodeContext::Text(TextContext { text_content: "Hello world".into(), writing_mode: WritingMode::Horizontal }),
)?;
taffy.add_child(node4, text)?;
println!("Compute layout with 100x100 viewport:");
taffy.compute_layout(
node1,
Size { height: AvailableSpace::Definite(100.0), width: AvailableSpace::Definite(100.0) },
)?;
println!("node: {:#?}", taffy.layout(node1)?);
println!("child: {:#?}", taffy.layout(node2)?);
println!("Compute layout with undefined (infinite) viewport:");
taffy.compute_layout(node1, Size::MAX_CONTENT)?;
println!("node: {:#?}", taffy.layout(node1)?);
println!("child: {:#?}", taffy.layout(node2)?);
taffy.print_tree(node1);
Ok(())
} And this leads to crash in bevy code here because bevy/crates/bevy_ui/src/ui_node.rs Lines 2386 to 2401 in cca6a2b
I am not sure if this is a bug in taffy or is it normal for it to return negative size. |
Negative widths being returned is surprising to me, but @nicoburns will know better if that's a taffy bug or something that Bevy needs to be robust to. |
Yeah we assume that the node size returned from Taffy is always positive. Afaik the sizes should never be negative. |
Negative node size seems wrong to me. I'll need to look into why this is happening in this case. |
Bevy version 0.15.0
(0.14.2 also had this issue)
What you did
I created a UI node hierarchy, that looks like this:
I know, it kinda does not make sense as there is a node with 100% size and parent size is not defined, but that should not crash anyway...
The code:
What went wrong
It crashes.
The text was updated successfully, but these errors were encountered: