diff options
| author | Sébastien Crozet <developer@crozet.re> | 2022-11-27 12:13:08 +0100 |
|---|---|---|
| committer | Sébastien Crozet <developer@crozet.re> | 2022-12-11 15:20:33 +0100 |
| commit | 7e95cba09dbaccdc60e9bc79a9d280577618843a (patch) | |
| tree | bc9ca76d50193c635c1736c9dbd261152a530e44 /src | |
| parent | 683baf6bf77cfb41227ea6ed4a42499d1e051cdf (diff) | |
| download | rapier-7e95cba09dbaccdc60e9bc79a9d280577618843a.tar.gz rapier-7e95cba09dbaccdc60e9bc79a9d280577618843a.tar.bz2 rapier-7e95cba09dbaccdc60e9bc79a9d280577618843a.zip | |
Fix ABA problem in incremental query pipeline update
Diffstat (limited to 'src')
| -rw-r--r-- | src/pipeline/query_pipeline.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/pipeline/query_pipeline.rs b/src/pipeline/query_pipeline.rs index 8a667de..a248426 100644 --- a/src/pipeline/query_pipeline.rs +++ b/src/pipeline/query_pipeline.rs @@ -330,14 +330,21 @@ impl QueryPipeline { removed_colliders: &[ColliderHandle], refit_and_rebalance: bool, ) { - for modified in modified_colliders { - self.qbvh.pre_update_or_insert(*modified); - } - + // We remove first. This is needed to avoid the ABA problem: if a collider was removed + // 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 { 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 { let _ = self.qbvh.refit(0.0, &mut self.workspace, |handle| { colliders[*handle].compute_aabb() |
