Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions crates/rapier3d/tests/persistent_islands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,61 @@ fn type_change_bridges_and_unbridges() {
);
}

/// Bodies turned fixed used to stay in the active set, so they were still
/// processed every step. They must leave it, and come back exactly once when
/// turned dynamic again.
#[test]
fn fixed_bodies_leave_the_active_set_and_reactivate() {
let mut world = PhysicsWorld::new();
world.gravity = Vector::ZERO;
let handles: Vec<_> = (0..8)
.map(|i| {
world
.insert(
RigidBodyBuilder::dynamic()
.can_sleep(false)
.translation(Vector::new(i as Real * 2.0, 10.0, 0.0)),
ColliderBuilder::cuboid(0.5, 0.5, 0.5),
)
.0
})
.collect();
let frozen = &handles[..handles.len() - 1];
let survivor = *handles.last().unwrap();

world.step();
assert_eq!(world.islands.num_active_bodies(), handles.len());

for &handle in frozen {
world.bodies[handle].set_body_type(RigidBodyType::Fixed, false);
}
world.step();

assert_eq!(
world.islands.active_bodies().collect::<Vec<_>>(),
[survivor]
);
for &handle in frozen {
assert_eq!(island_of(&world, handle), None);
}

for &handle in frozen {
world.bodies[handle].set_body_type(RigidBodyType::Dynamic, true);
}
world.gravity = Vector::new(0.0, -9.81, 0.0);
for _ in 0..30 {
world.step();
}

assert_eq!(world.islands.num_active_bodies(), handles.len());
let active: std::collections::HashSet<_> = world.islands.active_bodies().collect();
assert_eq!(active.len(), handles.len());
for handle in handles {
assert!(active.contains(&handle));
assert!(world.bodies[handle].translation().y < 9.0);
}
}

/// Disabling the middle box must split the row; re-enabling must re-merge it.
#[test]
fn disable_enable_bridges_and_unbridges() {
Expand Down
12 changes: 9 additions & 3 deletions src/dynamics/island_manager/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,15 @@ impl IslandManager {
};

if rb.is_fixed() {
// A body turned fixed leaves the persistent islands (fixed bodies
// are never island members).
self.persistent.remove_body(bodies, handle);
// Fixed bodies belong to neither persistent nor active/sleeping islands.
if rb.ids.active_island_id == u32::MAX {
self.persistent.remove_body(bodies, handle);
} else {
// A body turned fixed must also leave its active/sleeping island,
// just like a disabled body, or it keeps being processed every step.
let ids = rb.ids;
self.rigid_body_removed_or_disabled(handle, &ids, bodies);
}
return;
}

Expand Down