dimforge / nphysics

2 and 3-dimensional rigid body physics engine for Rust.
https://nphysics.org
Apache License 2.0
1.62k stars 121 forks source link

Crash in ragdoll3 example when dragging a ragdoll around #234

Open burjui opened 5 years ago

burjui commented 5 years ago

HEAD: 314bade

The first kind of crash can be reproduced pretty reliably by making a single ragdoll stuck in the platform and then dragging it around furiously until it passes through: https://youtu.be/6nXL79nJV7M

On one occasion this happened randomly even before any ragdoll stuck: https://youtu.be/KhtL3aqTDm8

Backtrace:

thread 'main' panicked at 'assertion failed: min_bound == min_bound', /home/burjui/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide3d-0.20.1/src/query/algorithms/gjk.rs:318:9
stack backtrace:
   0:     0x557960fea298 - backtrace::backtrace::libunwind::trace::hfe5db90796807973
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
   1:     0x557960fea298 - backtrace::backtrace::trace_unsynchronized::h34b865a835594335
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/mod.rs:66
   2:     0x557960fea298 - std::sys_common::backtrace::_print::h527254ae44989167
                               at src/libstd/sys_common/backtrace.rs:47
   3:     0x557960fea298 - std::sys_common::backtrace::print::he85dd5ddddf46503
                               at src/libstd/sys_common/backtrace.rs:36
   4:     0x557960fea298 - std::panicking::default_hook::{{closure}}::h847a2eb38b396f14
                               at src/libstd/panicking.rs:200
   5:     0x557960fe99f8 - std::panicking::default_hook::h2ca0f9a30a0e206b
                               at src/libstd/panicking.rs:214
   6:     0x557960fe99f8 - std::panicking::rust_panic_with_hook::hffcefc09751839d1
                               at src/libstd/panicking.rs:477
   7:     0x557960d8a9a4 - std::panicking::begin_panic::hdaa2c6457d26e4a5
   8:     0x557960d5b181 - ncollide3d::query::algorithms::gjk::cast_ray::h798d373ebdde898a
   9:     0x557960d5d9b6 - ncollide3d::query::ray::ray_support_map::<impl ncollide3d::query::ray::ray::RayCast<N> for ncollide3d::shape::capsule::Capsule<N>>::toi_and_normal_with_ray::h4e84db7c3da5c371
  10:     0x557960db0725 - <ncollide3d::pipeline::glue::query::InterferencesWithRay<N,Objects> as core::iter::traits::iterator::Iterator>::next::h91028a1fee708dcc
  11:     0x557960df4435 - <nphysics_testbed3d::testbed::Testbed as kiss3d::window::state::State>::step::hbeba048060d708e1
  12:     0x557960def8f2 - nphysics_testbed3d::testbed::Testbed::run::h97fe67eb43f5fe3e
  13:     0x557960d98bd5 - ragdoll3::main::ha5e53870a40f6722
  14:     0x557960d8a973 - std::rt::lang_start::{{closure}}::h26d49a7699508ac5
  15:     0x557960d993ce - main
  16:     0x7f3a6fb4eee3 - __libc_start_main
  17:     0x557960d4830e - _start
  18:                0x0 - <unknown>

The second kind happens usually when multiple ragdolls are stuck: https://youtu.be/i7PrM-kAQTQ https://youtu.be/nTEpTm-BBzA

Backtrace:

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libcore/slice/mod.rs:2681:10
stack backtrace:
   0:     0x55654e4e8298 - backtrace::backtrace::libunwind::trace::hfe5db90796807973
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
   1:     0x55654e4e8298 - backtrace::backtrace::trace_unsynchronized::h34b865a835594335
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/mod.rs:66
   2:     0x55654e4e8298 - std::sys_common::backtrace::_print::h527254ae44989167
                               at src/libstd/sys_common/backtrace.rs:47
   3:     0x55654e4e8298 - std::sys_common::backtrace::print::he85dd5ddddf46503
                               at src/libstd/sys_common/backtrace.rs:36
   4:     0x55654e4e8298 - std::panicking::default_hook::{{closure}}::h847a2eb38b396f14
                               at src/libstd/panicking.rs:200
   5:     0x55654e4e79f8 - std::panicking::default_hook::h2ca0f9a30a0e206b
                               at src/libstd/panicking.rs:214
   6:     0x55654e4e79f8 - std::panicking::rust_panic_with_hook::hffcefc09751839d1
                               at src/libstd/panicking.rs:477
   7:     0x55654e4e751f - std::panicking::continue_panic_fmt::hc0f142c930c846fc
                               at src/libstd/panicking.rs:384
   8:     0x55654e4f34a6 - rust_begin_unwind
                               at src/libstd/panicking.rs:311
   9:     0x55654e4fd8fc - core::panicking::panic_fmt::h2daf88b2616ca2b2
                               at src/libcore/panicking.rs:85
  10:     0x55654e4fd3e4 - core::panicking::panic_bounds_check::h0537ade040df571e
                               at src/libcore/panicking.rs:61
  11:     0x55654e2668c4 - ncollide3d::shape::convex_polygonal_feature3::ConvexPolygonalFeature<N>::clip::hd64aeb96e0b16387
  12:     0x55654e287cde - <ncollide3d::pipeline::narrow_phase::contact_generator::convex_polyhedron_convex_polyhedron_manifold_generator::ConvexPolyhedronConvexPolyhedronManifoldGenerator<N> as ncollide3d::pipeline::narrow_phase::contact_generator::contact_manifold_generator::ContactManifoldGenerator<N>>::generate_contacts::h7a6e1e0f464eb4f7
  13:     0x55654e267d37 - ncollide3d::pipeline::narrow_phase::contact_generator::capsule_shape_manifold_generator::CapsuleShapeManifoldGenerator<N>::do_update::hb4bfa1b436000e39
  14:     0x55654e28209b - <ncollide3d::pipeline::narrow_phase::contact_generator::capsule_shape_manifold_generator::CapsuleShapeManifoldGenerator<N> as ncollide3d::pipeline::narrow_phase::contact_generator::contact_manifold_generator::ContactManifoldGenerator<N>>::generate_contacts::h24f8fb9935b1f12b
  15:     0x55654e31176a - ncollide3d::pipeline::narrow_phase::narrow_phase::NarrowPhase<N,Handle>::update_contact::hecb048bc6cab1937
  16:     0x55654e306fe9 - nphysics3d::world::geometrical_world::GeometricalWorld<N,Handle,CollHandle>::perform_narrow_phase::he9795cfd01e0fcc1
  17:     0x55654e3046ac - nphysics3d::world::mechanical_world::MechanicalWorld<N,Bodies,CollHandle>::step::hb55ac3b528b496a8
  18:     0x55654e2f3629 - <nphysics_testbed3d::testbed::Testbed as kiss3d::window::state::State>::step::hbeba048060d708e1
  19:     0x55654e2ed8f2 - nphysics_testbed3d::testbed::Testbed::run::h97fe67eb43f5fe3e
  20:     0x55654e296bd5 - ragdoll3::main::ha5e53870a40f6722
  21:     0x55654e288973 - std::rt::lang_start::{{closure}}::h26d49a7699508ac5
  22:     0x55654e2973ce - main
  23:     0x7fceed906ee3 - __libc_start_main
  24:     0x55654e24630e - _start
  25:                0x0 - <unknown>
sebcrozet commented 5 years ago

Thank you for reporting this! Poor ragdolls 😢

The first crash you are describing here is kind of expected. Under singificant stress, a multibody may break down numerically speaking (because it has to solve an extremely stiff system), leading to NaN into some joint values, leading to the min_bound == min_bound assertion failure. This is a limitation of the current numerical method we use for multibodies more than an implementation bug. Fixing this amounts to have some kind of fallback when the main multibody solver fails to converge to a sensible solution.

The second crash your are experiencing looks like an actual implementation bug on the collision detection algorithm.