From a0e20790160bd4a4adb96156148eca3ee8c8edf9 Mon Sep 17 00:00:00 2001 From: james7132 Date: Mon, 14 Nov 2022 15:07:52 -0800 Subject: [PATCH 1/3] Fix get_unchecked_manual --- crates/bevy_ecs/src/query/state.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index 18874fd107fae..245ff7dacb7b4 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -418,6 +418,7 @@ impl QueryState { let mut fetch = Q::init_fetch(world, &self.fetch_state, last_change_tick, change_tick); let mut filter = F::init_fetch(world, &self.filter_state, last_change_tick, change_tick); + let table_row = archetype.entity_table_row(location.index); let table = world .storages() .tables @@ -426,8 +427,8 @@ impl QueryState { Q::set_archetype(&mut fetch, &self.fetch_state, archetype, table); F::set_archetype(&mut filter, &self.filter_state, archetype, table); - if F::filter_fetch(&mut filter, entity, location.index) { - Ok(Q::fetch(&mut fetch, entity, location.index)) + if F::filter_fetch(&mut filter, entity, table_row) { + Ok(Q::fetch(&mut fetch, entity, table_row)) } else { Err(QueryEntityError::QueryDoesNotMatch(entity)) } From 75bbf48fe05bddca0885d6920d2ca4183bed2e65 Mon Sep 17 00:00:00 2001 From: james7132 Date: Mon, 14 Nov 2022 15:28:31 -0800 Subject: [PATCH 2/3] Add regression test --- crates/bevy_ecs/src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index 04bc2ed7ffec4..600fa7575517d 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -707,6 +707,29 @@ mod tests { assert!(i32_query.get(&world, a).is_err()); } + #[test] + fn query_get_works_across_sparse_removal() { + // Regresssion test for: /~https://github.com/bevyengine/bevy/issues/6623 + let mut world = World::new(); + let a = world.spawn((TableStored("abc"), SparseStored(123))).id(); + let b = world.spawn((TableStored("def"), SparseStored(456))).id(); + let c = world + .spawn((TableStored("ghi"), SparseStored(789), B(1))) + .id(); + + let mut query = world.query::<&TableStored>(); + assert_eq!(query.get(&world, a).unwrap(), &TableStored("abc")); + assert_eq!(query.get(&world, b).unwrap(), &TableStored("def")); + assert_eq!(query.get(&world, c).unwrap(), &TableStored("ghi")); + + world.entity_mut(b).remove::(); + world.entity_mut(c).remove::(); + + assert_eq!(query.get(&world, a).unwrap(), &TableStored("abc")); + assert_eq!(query.get(&world, b).unwrap(), &TableStored("def")); + assert_eq!(query.get(&world, c).unwrap(), &TableStored("ghi")); + } + #[test] fn remove_tracking() { let mut world = World::new(); From 2c7574d8614411bad364e1b655aa70e953339784 Mon Sep 17 00:00:00 2001 From: james7132 Date: Mon, 14 Nov 2022 15:30:24 -0800 Subject: [PATCH 3/3] One too many "s"es --- crates/bevy_ecs/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index 600fa7575517d..a91ed6634f1b6 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -709,7 +709,7 @@ mod tests { #[test] fn query_get_works_across_sparse_removal() { - // Regresssion test for: /~https://github.com/bevyengine/bevy/issues/6623 + // Regression test for: /~https://github.com/bevyengine/bevy/issues/6623 let mut world = World::new(); let a = world.spawn((TableStored("abc"), SparseStored(123))).id(); let b = world.spawn((TableStored("def"), SparseStored(456))).id();