rapier
rapier copied to clipboard
Crash when trying to remove multibody joints from a rigid body
I tried removing multibody joints one by one or all at once, but it seems no matter how I do it I get the same crash. Same thing also happens when I call rigid_body_set.remove(...)
for rbd_handle in rbd_handles.into_iter() {
c.physics.multibody_joint_set.remove_joints_attached_to_rigid_body(rbd_handle);
}
stacktrace
thread 'main' panicked at 'index out of bounds: the len is 2 but the index is 6', /home/darth/.cargo/registry/src/github.com-1ecc6299db9ec823/rapier2d-0.14.0/src/dynamics/joint/multibody_joint/multibody.rs:180:43
stack backtrace:
0: rust_begin_unwind
at /rustc/1f34da9ec8a85b6f86c5fa1c121ab6f88f2f4966/library/std/src/panicking.rs:584:5
1: core::panicking::panic_fmt
at /rustc/1f34da9ec8a85b6f86c5fa1c121ab6f88f2f4966/library/core/src/panicking.rs:142:14
2: core::panicking::panic_bounds_check
at /rustc/1f34da9ec8a85b6f86c5fa1c121ab6f88f2f4966/library/core/src/panicking.rs:84:5
3: <usize as core::slice::index::SliceIndex<[T]>>::index
at /rustc/1f34da9ec8a85b6f86c5fa1c121ab6f88f2f4966/library/core/src/slice/index.rs:242:10
4: core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
at /rustc/1f34da9ec8a85b6f86c5fa1c121ab6f88f2f4966/library/core/src/slice/index.rs:18:9
5: <alloc::vec::Vec<T,A> as core::ops::index::Index<I>>::index
at /rustc/1f34da9ec8a85b6f86c5fa1c121ab6f88f2f4966/library/alloc/src/vec/mod.rs:2595:9
6: rapier2d::dynamics::joint::multibody_joint::multibody::Multibody::remove_link
at /home/darth/.cargo/registry/src/github.com-1ecc6299db9ec823/rapier2d-0.14.0/src/dynamics/joint/multibody_joint/multibody.rs:180:43
7: rapier2d::dynamics::joint::multibody_joint::multibody_joint_set::MultibodyJointSet::remove
at /home/darth/.cargo/registry/src/github.com-1ecc6299db9ec823/rapier2d-0.14.0/src/dynamics/joint/multibody_joint/multibody_joint_set.rs:191:35
8: rapier2d::dynamics::joint::multibody_joint::multibody_joint_set::MultibodyJointSet::remove_joints_attached_to_rigid_body
at /home/darth/.cargo/registry/src/github.com-1ecc6299db9ec823/rapier2d-0.14.0/src/dynamics/joint/multibody_joint/multibody_joint_set.rs:252:17
Looks like there might be more than one bug related to this, I've stopped using multibody joints for a while (used impulse joints instead) and now that I tried it again with a different setup, I'm getting a crash in the same situation of removing rigid bodies with multibody joints, with a similar crash, but in a different part of rapier
Although looking at the source code of rapier it seems to be vaguely related.
thread 'main' panicked at 'No element at index', /home/darth/.cargo/registry/src/github.com-1ecc6299db9ec823/rapier2d-0.14.0/src/dynamics/solver/generic_velocity_ground_constraint.rs:62:24
stack backtrace:
0: rust_begin_unwind
at /rustc/1f34da9ec8a85b6f86c5fa1c121ab6f88f2f4966/library/std/src/panicking.rs:584:5
1: core::panicking::panic_fmt
at /rustc/1f34da9ec8a85b6f86c5fa1c121ab6f88f2f4966/library/core/src/panicking.rs:142:14
2: core::panicking::panic_display
at /rustc/1f34da9ec8a85b6f86c5fa1c121ab6f88f2f4966/library/core/src/panicking.rs:72:5
3: core::panicking::panic_str
at /rustc/1f34da9ec8a85b6f86c5fa1c121ab6f88f2f4966/library/core/src/panicking.rs:56:5
4: core::option::expect_failed
at /rustc/1f34da9ec8a85b6f86c5fa1c121ab6f88f2f4966/library/core/src/option.rs:1874:5
5: rapier2d::dynamics::solver::generic_velocity_ground_constraint::GenericVelocityGroundConstraint::generate
6: rapier2d::dynamics::solver::solver_constraints::SolverConstraints<rapier2d::dynamics::solver::velocity_constraint::AnyVelocityConstraint>::compute_generic_ground_constraints
at /home/darth/.cargo/registry/src/github.com-1ecc6299db9ec823/rapier2d-0.14.0/src/dynamics/solver/solver_constraints.rs:235:13
7: rapier2d::dynamics::solver::solver_constraints::SolverConstraints<rapier2d::dynamics::solver::velocity_constraint::AnyVelocityConstraint>::init
at /home/darth/.cargo/registry/src/github.com-1ecc6299db9ec823/rapier2d-0.14.0/src/dynamics/solver/solver_constraints.rs:148:9
8: rapier2d::dynamics::solver::island_solver::IslandSolver::init_and_solve
at /home/darth/.cargo/registry/src/github.com-1ecc6299db9ec823/rapier2d-0.14.0/src/dynamics/solver/island_solver.rs:54:9
9: rapier2d::pipeline::physics_pipeline::PhysicsPipeline::build_islands_and_solve_velocity_constraints
at /home/darth/.cargo/registry/src/github.com-1ecc6299db9ec823/rapier2d-0.14.0/src/pipeline/physics_pipeline.rs:223:17
10: rapier2d::pipeline::physics_pipeline::PhysicsPipeline::step
at /home/darth/.cargo/registry/src/github.com-1ecc6299db9ec823/rapier2d-0.14.0/src/pipeline/physics_pipeline.rs:539:13
In this case the crash is when indexing into multibodies[m.multibody]
let (mb2, link_id2) = handle2
.and_then(|h| multibodies.rigid_body_link(h))
.map(|m| (&multibodies[m.multibody], m.id))
.unwrap();
Let me know if you need an example project to reproduce this, so far it seems to happen 100% consistently when removing joints, tho it does not crash on removal of every single joint. Some joints get removed without problems, but removing joints towards the end of a chain always crashes.