dimforge / dimforge/bevy_rapier
Panic on unreachable code on 2 rigidbodies with CCD intersecting with a bigger trimesh collider
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 282
- PR merge metrics
- No merged PRs in 30d
Description
I decided to try enabling CCD on some dynamic rigid bodies in a project, and immediately noticed crashes on unreachable code. The error seems to originate from Parry, but I'm unfamiliar with neither raw Parry nor Rapier, and can only provide example code as a Bevy project, so I feel like it's better if I post this issue here.
It seems to happen with the latest `bevy` and `bevy_rapier3d` crates on latest versions as of now, with default features compiled from a fresh new crate (see `Cargo.toml` below for exact versions).
Trying this on Arch Linux on Intel i5-8250U CPU on rustc 1.70.0.
```
thread 'Compute Task Pool (0)' panicked at 'internal error: entered unreachable code', /home/architector4/.cargo/registry/src/index.crates.io-6f17d22bba15001f/parry3d-0.13.4/src/query/nonlinear_time_of_impact/nonlinear_time_of_impact_support_map_support_map.rs:201:40
```
Here's an example project; click **twice** to immediately crash the application:
Cargo.toml
```
[package]
name = "bevydebug"
version = "0.1.0"
edition = "2021"
[dependencies]
bevy = "0.10.1"
bevy_rapier3d = "0.21.0"
```
src/main.rs
```
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;
fn spawn_dynamic(mut commands: Commands, input_mouse: Res>) {
if input_mouse.pressed(MouseButton::Left) {
commands.spawn((
RigidBody::Dynamic,
Ccd { enabled: true },
Collider::cuboid(0.5, 0.5, 0.5),
));
}
}
fn setup(mut commands: Commands) {
let some_mesh: Mesh = shape::Box::default().into();
let collider = Collider::from_bevy_mesh(&some_mesh, &ComputedColliderShape::TriMesh).unwrap();
commands.spawn(Camera3dBundle {
transform: Transform {
translation: Vec3::new(0.0, 10.0, 10.0),
rotation: Quat::from_rotation_x(-0.8),
..default()
},
..default()
});
commands.spawn((
collider,
SpatialBundle {
transform: Transform {
scale: Vec3 {
x: 1.1,
y: 1.0,
z: 1.0,
},
..default()
},
..default()
},
));
}
pub fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(RapierDebugRenderPlugin::default())
.add_plugin(RapierPhysicsPlugin::::default())
.add_startup_system(setup)
.add_system(spawn_dynamic)
.run();
}
```
From experimentation, it appears that this specifically happens when there is a static rigid body with a computed collider from a mesh (using `Collider` type's presets like `cuboid` don't seem to cause the crash, it has to be a trimesh) and 2 dynamic rigid bodies with any type of collider but with CCD on (even with default of 1 substep) that are smaller than the static one are found to be all intersecting with each other.
I haven't tested them intersecting in any other configuration than all 3 bodies at once. Any collider shapes and types seem to work, as long as one of the bodies is a trimesh collider that is bigger than the rest (it can also be a dynamic rigid body, though then it can get a bit harder to reproduce the issue, with disabling gravity and more clicks needed).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.