Skip to content

Commit 668fb66

Browse files
committed
add failing test for removing multibody joints + stepping
This currently crashes when removing last multibody joint, it seems that a link in MultibodyJointSet::multibodies should be removed
1 parent cd7fc6e commit 668fb66

1 file changed

Lines changed: 103 additions & 0 deletions

File tree

  • src/dynamics/joint/multibody_joint

src/dynamics/joint/multibody_joint/mod.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,106 @@ mod multibody_workspace;
1717
mod multibody_ik;
1818
mod multibody_joint;
1919
mod unit_multibody_joint;
20+
21+
#[cfg(test)]
22+
mod test {
23+
use crate::prelude::{
24+
BroadPhaseMultiSap, CCDSolver, ColliderSet, ImpulseJointSet, IntegrationParameters,
25+
IslandManager, NarrowPhase, PhysicsPipeline, RigidBodySet,
26+
};
27+
use crate::prelude::{MultibodyJointSet, RevoluteJoint};
28+
use parry::math::Vector;
29+
30+
#[test]
31+
fn multibody_joint_remove_and_step() {
32+
let mut rnd = oorandom::Rand32::new(1234);
33+
34+
for k in 0..10 {
35+
let mut bodies = RigidBodySet::new();
36+
let mut multibody_joints = MultibodyJointSet::new();
37+
let mut colliders = ColliderSet::new();
38+
let mut impulse_joints = ImpulseJointSet::new();
39+
let mut islands = IslandManager::new();
40+
41+
let mut pipeline = PhysicsPipeline::new();
42+
let mut bf = BroadPhaseMultiSap::new();
43+
let mut nf = NarrowPhase::new();
44+
45+
let num_links = 100;
46+
let mut handles = vec![];
47+
48+
for _ in 0..num_links {
49+
use crate::prelude::RigidBodyBuilder;
50+
51+
handles.push(bodies.insert(RigidBodyBuilder::dynamic()));
52+
}
53+
54+
#[cfg(feature = "dim2")]
55+
let joint = RevoluteJoint::new();
56+
#[cfg(feature = "dim3")]
57+
let joint = RevoluteJoint::new(na::Vector::x_axis());
58+
59+
for i in 0..num_links - 1 {
60+
multibody_joints
61+
.insert(handles[i], handles[i + 1], joint, true)
62+
.unwrap();
63+
}
64+
pipeline.step(
65+
&Vector::zeros(),
66+
&IntegrationParameters::default(),
67+
&mut islands,
68+
&mut bf,
69+
&mut nf,
70+
&mut bodies,
71+
&mut colliders,
72+
&mut impulse_joints,
73+
&mut multibody_joints,
74+
&mut CCDSolver::new(),
75+
None,
76+
&(),
77+
&(),
78+
);
79+
match k {
80+
0 => {} // Remove in insertion order.
81+
1 => {
82+
// Remove from leaf to root.
83+
handles.reverse();
84+
}
85+
_ => {
86+
// Shuffle the vector a bit.
87+
// (This test checks multiple shuffle arrangements due to k > 2).
88+
for l in 0..num_links {
89+
handles.swap(l, rnd.rand_range(0..num_links as u32) as usize);
90+
}
91+
}
92+
}
93+
94+
for (i, handle) in handles.iter().enumerate() {
95+
dbg!(i);
96+
bodies.remove(
97+
*handle,
98+
&mut islands,
99+
&mut colliders,
100+
&mut impulse_joints,
101+
&mut multibody_joints,
102+
true,
103+
);
104+
pipeline.step(
105+
&Vector::zeros(),
106+
&IntegrationParameters::default(),
107+
&mut islands,
108+
&mut bf,
109+
&mut nf,
110+
&mut bodies,
111+
&mut colliders,
112+
&mut impulse_joints,
113+
&mut multibody_joints,
114+
&mut CCDSolver::new(),
115+
None,
116+
&(),
117+
&(),
118+
);
119+
}
120+
}
121+
}
122+
}

0 commit comments

Comments
 (0)