dimforge / ncollide

2 and 3-dimensional collision detection library in Rust.
https://ncollide.org
Apache License 2.0
922 stars 106 forks source link

assertion failed: min_bound == min_bound on update to 0.14 #182

Closed arturoc closed 6 years ago

arturoc commented 6 years ago

After updating to 0.14, the following code which worked before is now panicking on the above assertion when calling update on the world:

extern crate ncollide;
extern crate nalgebra;

use nalgebra::{Point3, Vector3, Isometry3, zero};
use ncollide::world::{CollisionWorld, GeometricQueryType, CollisionGroups};
use ncollide::bounding_volume::*;
use ncollide::shape::*;

fn main() {
    let mut world: CollisionWorld<Point3<f32>, Isometry3<f32>, ()> = CollisionWorld::new(0.02f32);
    let groups = CollisionGroups::new();
    let contacts_query = GeometricQueryType::Contacts(0.0, 0.0);

    let min = Point3::new(-0.5, -0.5, -0.1);
    let max = Point3::new(0.5, 0.5, 0.1);
    let bounding = AABB::new(min, max);
    let cuboid = Cuboid::new(bounding.half_extents());
    let shape = ShapeHandle::new(cuboid);

    let iso1 = Isometry3::new(Vector3::new(0., 0., 0.), zero());
    world.add(iso1, shape.clone(), groups, contacts_query, ());

    let iso2 = Isometry3::new(Vector3::new(0., 1., 0.), zero());
    world.add(iso2, shape, groups, contacts_query, ());

    world.update();
}

with backtrace:

stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:68
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:57
             at /checkout/src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:397
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:577
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:538
   6: ncollide_geometry::query::algorithms::gjk::project_origin_with_max_dist
             at ./<panic macros>:3
   7: ncollide_geometry::query::algorithms::gjk::closest_points_with_max_dist
             at /home/arturo/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide_geometry-0.6.0/query/algorithms/gjk.rs:82
   8: ncollide_geometry::query::contacts_internal::support_map_against_support_map::support_map_against_support_map_with_params
             at /home/arturo/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide_geometry-0.6.0/query/contacts_internal/support_map_against_support_map.rs:108
   9: <ncollide_pipeline::narrow_phase::contact_generator::support_map_support_map_contact_generator::SupportMapSupportMapContactGenerator<P, M, S> as ncollide_pipeline::narrow_phase::contact_generator::contact_generator::ContactGenerator<P, M>>::update
             at /home/arturo/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide_pipeline-0.13.0/narrow_phase/contact_generator/support_map_support_map_contact_generator.rs:69
  10: <ncollide_pipeline::narrow_phase::contact_generator::incremental_contact_manifold_generator::IncrementalContactManifoldGenerator<P, M, CD>>::add_new_contacts
             at /home/arturo/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide_pipeline-0.13.0/narrow_phase/contact_generator/incremental_contact_manifold_generator.rs:110
  11: <ncollide_pipeline::narrow_phase::contact_generator::one_shot_contact_manifold_generator::OneShotContactManifoldGenerator<P, M, CD> as ncollide_pipeline::narrow_phase::contact_generator::contact_generator::ContactGenerator<P, M>>::update::{{closure}}
             at /home/arturo/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide_pipeline-0.13.0/narrow_phase/contact_generator/one_shot_contact_manifold_generator.rs:68
  12: nalgebra::core::matrix_alga::<impl alga::linear::vector::FiniteDimInnerSpace for nalgebra::core::matrix::Matrix<N, R, C, <nalgebra::core::default_allocator::DefaultAllocator as nalgebra::core::allocator::Allocator<N, R, C>>::Buffer>>::orthonormal_subspace_basis
             at /home/arturo/.cargo/registry/src/github.com-1ecc6299db9ec823/nalgebra-0.14.0/src/core/matrix_alga.rs:278
  13: <ncollide_pipeline::narrow_phase::contact_generator::one_shot_contact_manifold_generator::OneShotContactManifoldGenerator<P, M, CD> as ncollide_pipeline::narrow_phase::contact_generator::contact_generator::ContactGenerator<P, M>>::update
             at /home/arturo/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide_pipeline-0.13.0/narrow_phase/contact_generator/one_shot_contact_manifold_generator.rs:59
  14: <ncollide_pipeline::narrow_phase::default_narrow_phase::DefaultNarrowPhase<P, M> as ncollide_pipeline::narrow_phase::narrow_phase::NarrowPhase<P, M, T>>::update
             at /home/arturo/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide_pipeline-0.13.0/narrow_phase/default_narrow_phase.rs:54
  15: <ncollide_pipeline::world::collision_world::CollisionWorld<P, M, T>>::perform_narrow_phase
             at /home/arturo/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide_pipeline-0.13.0/world/collision_world.rs:195
  16: <ncollide_pipeline::world::collision_world::CollisionWorld<P, M, T>>::update
             at /home/arturo/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide_pipeline-0.13.0/world/collision_world.rs:97
  17: test_ncollide::main
             at src/main.rs:28
  18: __rust_maybe_catch_panic
             at /checkout/src/libpanic_unwind/lib.rs:101
  19: std::rt::lang_start
             at /checkout/src/libstd/panicking.rs:459
             at /checkout/src/libstd/panic.rs:365
             at /checkout/src/libstd/rt.rs:58
  20: main
  21: __libc_start_main
  22: _start
gui1117 commented 6 years ago

I don't know if this assert min_bound == min_bound should be min_bound == max_bound, because otherwise it would be better to write assert!(!min_bound.is_nan())

also it panics because it is NaN. ./ncollide_pipeline/narrow_phase/contact_generator/one_shot_contact_manifold_generator.rs:59 println!("{}", coll.normal.as_ref()); prints NaN

sebcrozet commented 6 years ago

This issue is due to a regression in the handling of objects that are just touching, i.e., separated by a distance of 0, but not penetrating.

The assertion min_bound == min_bound should indeed be min_bound.is_nan(), though it is not because it does not exists for the associated type P::Real.

arturoc commented 6 years ago

thanks for the quick fix! is there any possibility that you create a 0.14.1 fix release with this? right now 0.14 is crashing for anything that has shapes that are touching like these ones.

sebcrozet commented 6 years ago

@arturoc I've made a release that includes the fix just now.

arturoc commented 6 years ago

thanks!