-
-
Notifications
You must be signed in to change notification settings - Fork 335
Open
Description
I am hitting a panic caused by Option::unwrap() in Rapier2D. Here is a small reproducable example that panics upon being run:
use rapier2d::math::Vec2;
fn main() {
let mut physics = PhysicsWorld::new();
// this line has no effect, panic still happens if commented out:
physics.step();
// this line has no effect, panic still happens if commented out:
physics.add_box_collider(Vec2::new(0.0, -10.0), Vec2::new(100.0, 20.0));
let query_pipeline = physics.broad_phase.as_query_pipeline(
physics.narrow_phase.query_dispatcher(),
&physics.rigid_body_set,
&physics.collider_set,
rapier2d::prelude::QueryFilter::only_dynamic(),
);
let point = rapier2d::glamx::Vec2::new(-2.5586283, 2.1454737);
let res = query_pipeline.project_point(point, f32::MAX, true);
println!("Result: {res:?}");
}
struct PhysicsWorld {
gravity: f32,
rigid_body_set: rapier2d::dynamics::RigidBodySet,
collider_set: rapier2d::geometry::ColliderSet,
integration_parameters: rapier2d::dynamics::IntegrationParameters,
physics_pipeline: rapier2d::pipeline::PhysicsPipeline,
island_manager: rapier2d::dynamics::IslandManager,
broad_phase: rapier2d::geometry::DefaultBroadPhase,
narrow_phase: rapier2d::geometry::NarrowPhase,
impulse_joint_set: rapier2d::dynamics::ImpulseJointSet,
multibody_joint_set: rapier2d::dynamics::MultibodyJointSet,
ccd_solver: rapier2d::dynamics::CCDSolver,
}
impl PhysicsWorld {
pub fn new() -> Self {
let integration_parameters = rapier2d::dynamics::IntegrationParameters::default();
Self {
gravity: 9.81,
rigid_body_set: rapier2d::dynamics::RigidBodySet::new(),
collider_set: rapier2d::geometry::ColliderSet::new(),
integration_parameters,
physics_pipeline: rapier2d::pipeline::PhysicsPipeline::new(),
island_manager: rapier2d::dynamics::IslandManager::new(),
broad_phase: rapier2d::geometry::DefaultBroadPhase::new(),
narrow_phase: rapier2d::geometry::NarrowPhase::new(),
impulse_joint_set: rapier2d::dynamics::ImpulseJointSet::new(),
multibody_joint_set: rapier2d::dynamics::MultibodyJointSet::new(),
ccd_solver: rapier2d::dynamics::CCDSolver::new(),
}
}
pub fn step(&mut self) {
self.physics_pipeline.step(
rapier2d::glamx::Vec2::new(0.0, -self.gravity),
&self.integration_parameters,
&mut self.island_manager,
&mut self.broad_phase,
&mut self.narrow_phase,
&mut self.rigid_body_set,
&mut self.collider_set,
&mut self.impulse_joint_set,
&mut self.multibody_joint_set,
&mut self.ccd_solver,
&(),
&(),
);
}
pub fn add_box_collider(
&mut self,
pos: Vec2,
size: Vec2,
) -> rapier2d::geometry::ColliderHandle {
let collider = rapier2d::geometry::ColliderBuilder::cuboid(size.x * 0.5, size.y * 0.5)
.translation(rapier2d::glamx::Vec2::new(pos.x, pos.y));
self.collider_set.insert(collider)
}
}The panic:
thread 'main' (1141160) panicked at /home/tadeo/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/parry2d-0.26.0/src/query/point/point_composite_shape.rs:78:14:
called `Option::unwrap()` on a `None` value
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels