dimforge / rapier

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

rapier3d PhysicsPipeline panic on step in /src/partitioning/qbvh/update.rs:367:54 #532

Closed honnisha closed 6 months ago

honnisha commented 12 months ago

Rapier 3d version: rapier3d = { version = "0.17.2", features = [ "simd-stable" ] }

I'm running this code:

    pub fn step(&mut self, physics_container: &PhysicsContainer) {
        let physics_hooks = ();
        let event_handler = ();
        self.physics_pipeline.step(
            &self.gravity,
            &self.integration_parameters,
            &mut physics_container.island_manager.write(),
            &mut self.broad_phase,
            &mut self.narrow_phase,
            &mut physics_container.rigid_body_set.write(),
            &mut physics_container.collider_set.write(),
            &mut self.impulse_joint_set,
            &mut self.multibody_joint_set,
            &mut self.ccd_solver,
            Some(&mut physics_container.query_pipeline.write()),
            &physics_hooks,
            &event_handler,
        );
    }

Panic:

thread '<unnamed>' panicked at 'attempt to add with overflow', /home/honnisha/.cargo/registry/src/index.crates.io-6f17d22bba15001f/parry3d-0.13.5/src/partitioning/qbvh/update.rs:367:54
stack backtrace:
   0: rust_begin_unwind
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/panicking.rs:67:14
   2: core::panicking::panic
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/panicking.rs:117:5
   3: parry3d::partitioning::qbvh::update::<impl parry3d::partitioning::qbvh::qbvh::GenericQbvh<LeafData,parry3d::utils::array::DefaultStorage>>::rebalance
             at /home/honnisha/.cargo/registry/src/index.crates.io-6f17d22bba15001f/parry3d-0.13.5/src/partitioning/qbvh/update.rs:367:54
   4: rapier3d::pipeline::query_pipeline::QueryPipeline::update_incremental
             at /home/honnisha/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rapier3d-0.17.2/src/pipeline/query_pipeline.rs:352:13
   5: rapier3d::pipeline::physics_pipeline::PhysicsPipeline::step
             at /home/honnisha/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rapier3d-0.17.2/src/pipeline/physics_pipeline.rs:624:17
   6: honny_client::world::physics_handler::PhysicsController::step
             at /home/honnisha/godot/honny-craft/honny-client/src/world/physics_handler.rs:263:9
   7: honny_client::world::physics_handler::PhysicsContainer::step
             at /home/honnisha/godot/honny-craft/honny-client/src/world/physics_handler.rs:206:9
   8: <honny_client::world::godot_world::World as godot_core::gen::classes::node::re_export::NodeVirtual>::process
             at /home/honnisha/godot/honny-craft/honny-client/src/world/godot_world.rs:158:9
   9: <honny_client::world::godot_world::World as godot_core::obj::traits::cap::ImplementsGodotVirtual>::__virtual_call::function::{{closure}}
             at /home/honnisha/godot/honny-craft/honny-client/src/world/godot_world.rs:125:1
  10: core::ops::function::FnOnce::call_once
             at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/ops/function.rs:250:5
  11: <(R,P0) as godot_core::builtin::meta::signature::PtrcallSignatureTuple>::in_ptrcall
             at /home/honnisha/.cargo/git/checkouts/gdext-76630c89719e160c/a92164b/godot-core/src/builtin/meta/signature.rs:274:38
  12: <honny_client::world::godot_world::World as godot_core::obj::traits::cap::ImplementsGodotVirtual>::__virtual_call::function
             at /home/honnisha/godot/honny-craft/honny-client/src/world/godot_world.rs:125:1
  13: <unknown>
  14: <unknown>
  15: <unknown>
  16: <unknown>
  17: <unknown>
  18: <unknown>
  19: <unknown>
  20: <unknown>
  21: __libc_start_main
  22: <unknown>

Maybe its related to https://github.com/dimforge/rapier/issues/450

Ralith commented 11 months ago

Just hit this myself, in connection with a body going from dynamic to kinematic, and the reverse.

honnisha commented 11 months ago

I'm trying to figure out what the cause is. I have added logs before the line where error occurs

parry/src/partitioning/qbvh/update.rs

                    if child < self.nodes.len() as u32 {
                        if depth == u8::MAX {
                            println!("workspace.stack.len():{} child:{} depth:{}", workspace.stack.len(), child, depth);
                        }
                        workspace.stack.push((child, depth + 1));
                    }

Output:

workspace.stack.len():8 child:7917 depth:255
thread '<unnamed>' panicked at /home/honnisha/Projects/parry/crates/parry3d/../../src/partitioning/qbvh/update.rs:370:54:

My code switches activity of the colliders if the player moves forward/away from them. And right after the switch this error occurs sometimes.

honnisha commented 11 months ago

Created pr to fix this issue https://github.com/dimforge/parry/pull/169

Ralith commented 11 months ago

Why would changing a rigid body type require an unusually large stack depth? I suspect the stack size might be a symptom of a more basic issue.