Skip to content
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

default inherited visibility when parent has invalid components #10275

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions crates/bevy_render/src/view/visibility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ fn visibility_propagate_system(
let is_visible = match visibility {
Visibility::Visible => true,
Visibility::Hidden => false,
Visibility::Inherited => match parent {
None => true,
Some(parent) => visibility_query.get(parent.get()).unwrap().1.get(),
},
// fall back to true if no parent is found or parent lacks components
Visibility::Inherited => parent
.and_then(|p| visibility_query.get(p.get()).ok())
.map_or(true, |(_, x)| x.get()),
};
let (_, mut inherited_visibility) = visibility_query
.get_mut(entity)
Expand Down Expand Up @@ -721,6 +721,24 @@ mod test {
assert!(!q.get(&world, id4).unwrap().is_changed());
}

#[test]
fn visibility_propagation_with_invalid_parent() {
let mut world = World::new();
let mut schedule = Schedule::default();
schedule.add_systems(visibility_propagate_system);

let parent = world.spawn(()).id();
let child = world.spawn(VisibilityBundle::default()).id();
world.entity_mut(parent).push_children(&[child]);

schedule.run(&mut world);
world.clear_trackers();

let child_visible = world.entity(child).get::<InheritedVisibility>().unwrap().0;
// defaults to same behavior of parent not found: visible = true
assert!(child_visible);
}

#[test]
fn ensure_visibility_enum_size() {
use std::mem;
Expand Down