Skip to content

Conversation

@ThierryBerger
Copy link
Contributor

@ThierryBerger ThierryBerger commented Jun 25, 2025

thread 'dynamics::joint::multibody_joint::test::multibody_joint_remove_and_step' panicked at crates/rapier2d/../../src/dynamics/solver/velocity_solver.rs:101:22:
called `Option::unwrap()` on a `None` value

⚠️ I easily make it crash by running cargo run --bin all_examples3 -> hitting a few times A (remove any 10% multibodies) with 2 scenari:

diff --git a/src/dynamics/joint/multibody_joint/multibody_joint_set.rs b/src/dynamics/joint/multibody_joint/multibody_joint_set.rs
index 3dd3e36..aac7538 100644
--- a/src/dynamics/joint/multibody_joint/multibody_joint_set.rs
+++ b/src/dynamics/joint/multibody_joint/multibody_joint_set.rs
@@ -250,8 +250,13 @@ impl MultibodyJointSet {
                             .connectivity_graph
                             .remove_node(isolated_graph_id.graph_id)
                         {
-                            self.rb2mb.get_mut(other.0).unwrap().graph_id =
-                                isolated_graph_id.graph_id;
+                            let other_mb_id = self.rb2mb.get_mut(other.0).unwrap();
+                            other_mb_id.graph_id = isolated_graph_id.graph_id;
+                            let other_mb_id = other_mb_id.clone();
+                            let other_mb = self.multibodies.get(other_mb_id.multibody.0).unwrap();
+                            if other_mb.num_links() == 1 {
+                                self.remove(MultibodyJointHandle(other_mb_id.multibody.0), wake_up);
+                            }
                         }
                     } else {
                         let mb_id = self.multibodies.insert(multibody);

This currently crashes when removing last multibody joint, it seems that a link in MultibodyJointSet::multibodies should be removed
use parry::math::Vector;

#[test]
fn multibody_joint_remove_and_step() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost same content as multibody::test_multibody_remove but adds a simulation step between each removal

@ThierryBerger ThierryBerger requested a review from sebcrozet July 4, 2025 14:12
Comment on lines +91 to +99
if let Some(link) = multibody_joints.rigid_body_link(*handle).copied() {
if multibody_joints
.get_multibody_mut_internal(link.multibody)
.is_none()
{
panic!("multibody_joints should be able to get all links returned from rigid_body_link.");
}
panic!("This test has only 1 link, it should lead to rigid_body_link returning `None` immediately after first removal.");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is added to catch at the earliest the original error of:

thread 'dynamics::joint::multibody_joint::test::multibody_joint_remove_and_step' panicked at crates/rapier2d/../../src/dynamics/solver/velocity_solver.rs:101:22:
called `Option::unwrap()` on a `None` value

⚠️ While this test pass, it's not enough because I can still make the example crash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant