Fix ABA problem in incremental query pipeline update
This commit is contained in:
@@ -330,14 +330,21 @@ impl QueryPipeline {
|
|||||||
removed_colliders: &[ColliderHandle],
|
removed_colliders: &[ColliderHandle],
|
||||||
refit_and_rebalance: bool,
|
refit_and_rebalance: bool,
|
||||||
) {
|
) {
|
||||||
for modified in modified_colliders {
|
// We remove first. This is needed to avoid the ABA problem: if a collider was removed
|
||||||
self.qbvh.pre_update_or_insert(*modified);
|
// and another added right after with the same handle index, we can remove first, and
|
||||||
}
|
// then update the new one (but only if its actually exists, to address the case where
|
||||||
|
// a collider was added/modified and then removed during the same frame).
|
||||||
for removed in removed_colliders {
|
for removed in removed_colliders {
|
||||||
self.qbvh.remove(*removed);
|
self.qbvh.remove(*removed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for modified in modified_colliders {
|
||||||
|
// Check that the collider still exists as it may have been removed.
|
||||||
|
if colliders.contains(*modified) {
|
||||||
|
self.qbvh.pre_update_or_insert(*modified);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if refit_and_rebalance {
|
if refit_and_rebalance {
|
||||||
let _ = self.qbvh.refit(0.0, &mut self.workspace, |handle| {
|
let _ = self.qbvh.refit(0.0, &mut self.workspace, |handle| {
|
||||||
colliders[*handle].compute_aabb()
|
colliders[*handle].compute_aabb()
|
||||||
|
|||||||
Reference in New Issue
Block a user