Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tricky bug with "failed assertion e.floor() < RegionKey::MAX as Real", maybe related to RigidBody.set_enabled() #783

Open
bcolloran opened this issue Jan 8, 2025 · 0 comments

Comments

@bcolloran
Copy link

Hi, I'm hoping someone can point me in the right direction of how to start debugging this issue, my code is somehow triggering an assertion that is deep enough within Rapier's internals that I'm not really sure where to start figuring what is going wrong, nor how to create a minimal reproduction case.

Somehow, the expected invariant from this line of code --assert!(e.floor() < RegionKey::MAX as Real); -- is being violated.

The best clue I have is that I'm trying to disable bodies with rapier2d::dynamics::rigid_body::RigidBody.set_enabled() (link to code). I only invoke this in one place in my code, and if I comment out that line, the crash seems to go away.

Some more details in case this sparks any ideas:
I'm trying to disable a player body when it is hit with a projectile, at the same instant I despawn an overlapping projectile body. Each body has a single RigidBody collider; additionally the player has several attached sensor colliders and the projectile has one attached sensor. So it may be the case that between two Rapier steps, two bodies with multiple overlapping sensor are despawned and disabled.

I kind of wonder if this is perhaps an unexpected edge case that is not covered by the invariant above, and that is causing the broad phase to crash somehow? But, again, since this is pretty deep in the internals I'm not really sure what this invariant means of how my user code could be causing it to be violated.

I apologize that this is a somewhat nebulous bug report, I'm just a little out of my depth so I'm not sure what info would be helpful. Happy to supply more info if you can point me in the direction of other details that might be useful. For whatever it's worth, below is a stack trace from adding "std::backtrace::Backtrace::force_capture()" just above the assertion:

Thank you!

Backtrace [
{
  fn: "rapier2d::geometry::broad_phase_multi_sap::sap_utils::point_key::{{closure}}",
  file: "/local_crates/rapier/crates/rapier2d/../../src/geometry/broad_phase_multi_sap/sap_utils.rs",
  line: 39 }, 
{
  fn: "nalgebra::base::matrix::Matrix<T,R,C,S>::map",
  file: "~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/nalgebra-0.33.0/src/base/matrix.rs",
  line: 732 }, 
{
  fn: "rapier2d::geometry::broad_phase_multi_sap::sap_utils::point_key",
  file: "/local_crates/rapier/crates/rapier2d/../../src/geometry/broad_phase_multi_sap/sap_utils.rs",
  line: 32 }, 
{
  fn: "rapier2d::geometry::broad_phase_multi_sap::sap_layer::SAPLayer::predelete_proxy",
  file: "/local_crates/rapier/crates/rapier2d/../../src/geometry/broad_phase_multi_sap/sap_layer.rs",
  line: 283 }, 
{
  fn: "rapier2d::geometry::broad_phase_multi_sap::broad_phase_multi_sap::BroadPhaseMultiSap::predelete_proxy",
  file: "/local_crates/rapier/crates/rapier2d/../../src/geometry/broad_phase_multi_sap/broad_phase_multi_sap.rs",
  line: 176 }, 
{
  fn: "rapier2d::geometry::broad_phase_multi_sap::broad_phase_multi_sap::BroadPhaseMultiSap::handle_removed_colliders",
  file: "/local_crates/rapier/crates/rapier2d/../../src/geometry/broad_phase_multi_sap/broad_phase_multi_sap.rs",
  line: 154 }, 
{
  fn: "<rapier2d::geometry::broad_phase_multi_sap::broad_phase_multi_sap::BroadPhaseMultiSap as rapier2d::geometry::broad_phase::BroadPhase>::update",
  file: "/local_crates/rapier/crates/rapier2d/../../src/geometry/broad_phase_multi_sap/broad_phase_multi_sap.rs",
  line: 598 }, 
{
  fn: "rapier2d::pipeline::physics_pipeline::PhysicsPipeline::detect_collisions",
  file: "/local_crates/rapier/crates/rapier2d/../../src/pipeline/physics_pipeline.rs",
  line: 114 }, 
{
  fn: "rapier2d::pipeline::physics_pipeline::PhysicsPipeline::step",
  file: "/local_crates/rapier/crates/rapier2d/../../src/pipeline/physics_pipeline.rs",
  line: 484 }, 
{
  fn: "godot_test::physics::rapier_step::godot_to_rapier_physics_tick_and_back",
  file: "/godot_test/rust/src/physics/rapier_step.rs",
  line: 38 }, 
{
  fn: "godot_test::sim_state::sim_phases::step_sim::step_sim",
  file: "/godot_test/rust/src/sim_state/sim_phases/step_sim.rs",
  line: 127 }, 
{
  fn: "godot_test::physics::sim_server::SimServer::step_sim_inner",
  file: "/godot_test/rust/src/physics/sim_server.rs",
  line: 150 }, 
{
  fn: "godot_test::physics::sim_server::SimServer::do_sim_steps",
  file: "/godot_test/rust/src/physics/sim_server.rs",
  line: 289 }, 
{
  fn: "godot_test::physics::sim_server_godot_api::<impl godot_test::physics::sim_server::SimServer>::advance_sim",
  file: "/godot_test/rust/src/physics/sim_server_godot_api.rs",
  line: 142 }, 
{
  fn: "godot_test::physics::sim_server_godot_api::_::__init::__inner_init::{{closure}}::varcall_fn::{{closure}}::{{closure}}",
  file: "/godot_test/rust/src/physics/sim_server_godot_api.rs",
  line: 26 }, 
{
  fn: "core::ops::function::FnOnce::call_once",
  file: "~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs",
  line: 250 }, 
{
  fn: "<(R,) as godot_core::meta::signature::VarcallSignatureTuple>::in_varcall",
  file: "/local_crates/gdext/godot-core/src/meta/signature.rs",
  line: 192 }, 
{
  fn: "godot_test::physics::sim_server_godot_api::_::__init::__inner_init::{{closure}}::varcall_fn::{{closure}}",
  file: "/godot_test/rust/src/physics/sim_server_godot_api.rs",
  line: 26 }, 
{
  fn: "std::panicking::try::do_call",
  file: "~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs",
  line: 557 }, 
{
  fn: "__rust_try" }, 
{
  fn: "std::panicking::try",
  file: "~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs",
  line: 520 }, 
{
  fn: "std::panic::catch_unwind",
  file: "~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs",
  line: 358 }, 
{
  fn: "godot_core::private::handle_panic_with_print",
  file: "/local_crates/gdext/godot-core/src/private.rs",
  line: 375 }, 
{
  fn: "godot_core::private::handle_varcall_panic",
  file: "/local_crates/gdext/godot-core/src/private.rs",
  line: 287 }, 
{
  fn: "godot_test::physics::sim_server_godot_api::_::__init::__inner_init::{{closure}}::varcall_fn",
  file: "/godot_test/rust/src/physics/sim_server_godot_api.rs",
  line: 26 }, 
{
  fn: "__libc_start_call_main",
  file: "./csu/../sysdeps/nptl/libc_start_call_main.h",
  line: 58 }, 
{
  fn: "__libc_start_main_impl",
  file: "./csu/../csu/libc-start.c",
  line: 360 }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant