dimforge / rapier

2D and 3D physics engines focused on performance.
https://rapier.rs
Apache License 2.0
3.91k stars 244 forks source link

Index out of bounds in VelocityConstraint::warmstart #238

Closed Ralith closed 2 years ago

Ralith commented 2 years ago

Occurred while repeatedly switching a rigid body between RigidBodyType::KinematicPositionBased and RigidBodyType::Dynamic, overwriting the linear and angular velocity and position when transitioning back to dynamic. The panic happened while the object was kinematic.

Full stack trace:

thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1', C:\Users\Ralith\.cargo\registry\src\github.com-1ecc6299db9ec823\rapier3d-f64-0.11.0\src\dynamics\solver\velocity_constraint.rs:322:9
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633\/library\std\src\panicking.rs:515
   1: core::panicking::panic_fmt
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633\/library\core\src\panicking.rs:92
   2: core::panicking::panic_bounds_check
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633\/library\core\src\panicking.rs:69
   3: rapier3d_f64::dynamics::solver::velocity_constraint::VelocityConstraint::warmstart
             at C:\Users\Ralith\.cargo\registry\src\github.com-1ecc6299db9ec823\rapier3d-f64-0.11.0\src\dynamics\solver\velocity_constraint.rs:322
   4: enum$<rapier3d_f64::dynamics::solver::velocity_constraint::AnyVelocityConstraint>::warmstart
             at C:\Users\Ralith\.cargo\registry\src\github.com-1ecc6299db9ec823\rapier3d-f64-0.11.0\src\dynamics\solver\velocity_constraint.rs:47
   5: rapier3d_f64::dynamics::solver::velocity_solver::VelocitySolver::solve<rapier3d_f64::dynamics::rigid_body_set::RigidBodySet>
             at C:\Users\Ralith\.cargo\registry\src\github.com-1ecc6299db9ec823\rapier3d-f64-0.11.0\src\dynamics\solver\velocity_solver.rs:64
   6: rapier3d_f64::dynamics::solver::island_solver::IslandSolver::init_constraints_and_solve_velocity_constraints<rapier3d_f64::dynamics::rigid_body_set::RigidBodySet>
             at C:\Users\Ralith\.cargo\registry\src\github.com-1ecc6299db9ec823\rapier3d-f64-0.11.0\src\dynamics\solver\island_solver.rs:91
   7: rapier3d_f64::pipeline::physics_pipeline::PhysicsPipeline::build_islands_and_solve_velocity_constraints
             at C:\Users\Ralith\.cargo\registry\src\github.com-1ecc6299db9ec823\rapier3d-f64-0.11.0\src\pipeline\physics_pipeline.rs:290
   8: rapier3d_f64::pipeline::physics_pipeline::PhysicsPipeline::step_generic
             at C:\Users\Ralith\.cargo\registry\src\github.com-1ecc6299db9ec823\rapier3d-f64-0.11.0\src\pipeline\physics_pipeline.rs:655
   9: rapier3d_f64::pipeline::physics_pipeline::PhysicsPipeline::step
             at C:\Users\Ralith\.cargo\registry\src\github.com-1ecc6299db9ec823\rapier3d-f64-0.11.0\src\pipeline\physics_pipeline.rs:494
sebcrozet commented 2 years ago

This panic is caused by the fact that only modifying the type of a rigid-body won’t trigger an update of the relative_dominance stored in contact manifolds involving this rigid-body. Ultimately, this means that said contact manifold ends up in the wrong pool of contact manifolds (i.e. it may end up in the pool of two-bodies contact where it should only be one-body contact).

Will be fixed by #252.