From dc63c28f56c989ec97cb416d186cf76a1e61c555 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 24 Nov 2020 14:57:37 +0100 Subject: Fix crash when removing a collider with no graph ID. --- src/geometry/narrow_phase.rs | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/geometry/narrow_phase.rs b/src/geometry/narrow_phase.rs index 30c1f8c..cf7b531 100644 --- a/src/geometry/narrow_phase.rs +++ b/src/geometry/narrow_phase.rs @@ -137,25 +137,27 @@ impl NarrowPhase { let mut i = 0; while let Some(collider) = colliders.removed_colliders.read_ith(&cursor, i) { - let graph_idx = self.graph_indices.get(collider.handle).unwrap(); - - let proximity_graph_id = prox_id_remap - .get(&collider.handle) - .copied() - .unwrap_or(graph_idx.proximity_graph_index); - let contact_graph_id = contact_id_remap - .get(&collider.handle) - .copied() - .unwrap_or(graph_idx.contact_graph_index); - - self.remove_collider( - proximity_graph_id, - contact_graph_id, - colliders, - bodies, - &mut prox_id_remap, - &mut contact_id_remap, - ); + // NOTE: if the collider does not have any graph indices currently, there is nothing + // to remove in the narrow-phase for this collider. + if let Some(graph_idx) = self.graph_indices.get(collider.handle) { + let proximity_graph_id = prox_id_remap + .get(&collider.handle) + .copied() + .unwrap_or(graph_idx.proximity_graph_index); + let contact_graph_id = contact_id_remap + .get(&collider.handle) + .copied() + .unwrap_or(graph_idx.contact_graph_index); + + self.remove_collider( + proximity_graph_id, + contact_graph_id, + colliders, + bodies, + &mut prox_id_remap, + &mut contact_id_remap, + ); + } i += 1; } -- cgit