Skip to content

Commit

Permalink
Update observer archetype flags for sparse components (#13886)
Browse files Browse the repository at this point in the history
# Objective

- Fixes #13885 

## Solution

- Update the flags correctly on archetype creation

## Testing

- Added `observer_order_insert_remove_sparse` to catch regressions.
  • Loading branch information
james-j-obrien authored and mockersf committed Jun 19, 2024
1 parent b74b3b2 commit 5d5e67f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/bevy_ecs/src/archetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ impl Archetype {
// SAFETY: We are creating an archetype that includes this component so it must exist
let info = unsafe { components.get_info_unchecked(component_id) };
info.update_archetype_flags(&mut flags);
observers.update_archetype_flags(component_id, &mut flags);
archetype_components.insert(
component_id,
ArchetypeComponentInfo {
Expand Down
20 changes: 20 additions & 0 deletions crates/bevy_ecs/src/observer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ mod tests {
#[derive(Component)]
struct C;

#[derive(Component)]
#[component(storage = "SparseSet")]
struct S;

#[derive(Event)]
struct EventA;

Expand Down Expand Up @@ -444,6 +448,22 @@ mod tests {
assert_eq!(3, world.resource::<R>().0);
}

#[test]
fn observer_order_insert_remove_sparse() {
let mut world = World::new();
world.init_resource::<R>();

world.observe(|_: Trigger<OnAdd, S>, mut res: ResMut<R>| res.assert_order(0));
world.observe(|_: Trigger<OnInsert, S>, mut res: ResMut<R>| res.assert_order(1));
world.observe(|_: Trigger<OnRemove, S>, mut res: ResMut<R>| res.assert_order(2));

let mut entity = world.spawn_empty();
entity.insert(S);
entity.remove::<S>();
entity.flush();
assert_eq!(3, world.resource::<R>().0);
}

#[test]
fn observer_order_recursive() {
let mut world = World::new();
Expand Down

0 comments on commit 5d5e67f

Please sign in to comment.