Skip to content

Commit 58a3662

Browse files
authored
Create thread-local contact status bit vectors with the correct block count (#686)
# Objective Fixes #687. The narrow phase is currently initializing the thread-local contact status bit vectors with a block count of zero. This means that for the first tick, contact status changes might not be tracked correctly. The bitwise OR to combine the bit vectors also currently panics with debug assertions enabled, because the sizes of the vectors don't match. ## Solution Initialize thread-local contact status bit vectors with the correct block count. I also improved the error message for the debug assertion in `BitVec::or`.
1 parent 2ab588d commit 58a3662

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/collision/narrow_phase/system_param.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,13 @@ impl<C: AnyCollider> NarrowPhase<'_, '_, C> {
301301
// Get the thread-local bit vector for tracking status changes.
302302
let mut state_change_bits = self
303303
.contact_status_bits_thread_local
304-
.get_or(|| RefCell::new(BitVec::new(contact_pair_count)))
304+
.get_or(|| {
305+
// No thread-local bit vector exists for this thread yet.
306+
// Create a new one with the same capacity as the global bit vector.
307+
let mut bit_vec = BitVec::new(contact_pair_count);
308+
bit_vec.set_bit_count_and_clear(contact_pair_count);
309+
RefCell::new(bit_vec)
310+
})
305311
.borrow_mut();
306312

307313
let contacts = &mut contacts.weight;

src/data_structures/bit_vec.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ impl BitVec {
117117
/// Performs an in-place bitwise OR operation with another [`BitVec`].
118118
#[inline]
119119
pub fn or(&mut self, other: &Self) {
120-
debug_assert!(self.block_count == other.block_count);
120+
debug_assert!(
121+
self.block_count == other.block_count,
122+
"block counts do not match for `BitVec::or` ({} != {})",
123+
self.block_count,
124+
other.block_count
125+
);
121126

122127
for i in 0..self.block_count {
123128
self.blocks[i] |= other.blocks[i];

0 commit comments

Comments
 (0)