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

Index out of bounds with these two triangles #313

Closed
wlinna opened this issue Oct 7, 2019 · 2 comments
Closed

Index out of bounds with these two triangles #313

wlinna opened this issue Oct 7, 2019 · 2 comments
Labels
bug P-medium Medium priority

Comments

@wlinna
Copy link

wlinna commented Oct 7, 2019

The code below panics after world.update(); . These triangles are part of a larger model. Luckily, I was able to pinpoint these two triangles. There seemed to be other combinations too, but I don't what they are.

extern crate nalgebra as na;
use na::Point3;

fn main() {
    let mut world = ncollide3d::pipeline::CollisionWorld::<f32, ()>::new(0.02);
    let group = ncollide3d::pipeline::CollisionGroups::default();
    let origin = na::Isometry3::identity();

    let tri1 = ncollide3d::shape::ShapeHandle::new(ncollide3d::shape::Triangle::new(
        Point3::from_slice(&[6.292823, 6.456138, 19.66036]),
        Point3::from_slice(&[6.280472, 6.421245, 19.57066]),
        Point3::from_slice(&[6.275294, 6.449808, 19.57066]),
    ));
    let tri2 = ncollide3d::shape::ShapeHandle::new(ncollide3d::shape::Triangle::new(
        Point3::from_slice(&[6.292823, 6.456138, 19.66036]),
        Point3::from_slice(&[6.299445, 6.421245, 19.66036]),
        Point3::from_slice(&[6.280472, 6.421245, 19.57066]),
    ));

    let query_type = ncollide3d::pipeline::object::GeometricQueryType::Contacts(0.0, 0.0);

    world.add(origin, tri1, group, query_type, ());
    world.add(origin, tri2, group, query_type, ());
    world.update();
}

Here's the full backtrace:

thread 'main' panicked at 'index out of bounds: the len is 2 but the index is 2', /rustc/625451e376bb2e5283fc4741caa0a3e8a2ca4d54/src/libcore/slice/mod.rs:2721:14
stack backtrace:
   0:     0x55555569f9cb - backtrace::backtrace::libunwind::trace::h89fcc71e59e3bc5b
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/libunwind.rs:88
   1:     0x55555569f9cb - backtrace::backtrace::trace_unsynchronized::h0bad9be1379e729a
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/mod.rs:66
   2:     0x55555569f9cb - std::sys_common::backtrace::_print::hd3382a1f33c473da
                               at src/libstd/sys_common/backtrace.rs:47
   3:     0x55555569f9cb - std::sys_common::backtrace::print::h0ec6f03cfb8e76a6
                               at src/libstd/sys_common/backtrace.rs:36
   4:     0x55555569f9cb - std::panicking::default_hook::{{closure}}::h96cbf7b454e3f557
                               at src/libstd/panicking.rs:200
   5:     0x55555569f6a6 - std::panicking::default_hook::h95a8f00337383d83
                               at src/libstd/panicking.rs:214
   6:     0x5555556a008d - std::panicking::rust_panic_with_hook::h92f98b46e22f14ed
                               at src/libstd/panicking.rs:477
   7:     0x55555569fc12 - std::panicking::continue_panic_fmt::h25abfbb4e5b7043a
                               at src/libstd/panicking.rs:384
   8:     0x55555569faf6 - rust_begin_unwind
                               at src/libstd/panicking.rs:311
   9:     0x5555556b7bfd - core::panicking::panic_fmt::h7e9f94035af782b3
                               at src/libcore/panicking.rs:85
  10:     0x5555556b7bb5 - core::panicking::panic_bounds_check::hf0c95c4cc84d34ca
                               at src/libcore/panicking.rs:61
  11:     0x5555555c41d7 - <usize as core::slice::SliceIndex<[T]>>::index_mut::hbf6c8f008e4606d3
                               at /rustc/625451e376bb2e5283fc4741caa0a3e8a2ca4d54/src/libcore/slice/mod.rs:2721
  12:     0x555555569107 - core::slice::<impl core::ops::index::IndexMut<I> for [T]>::index_mut::h70c677233e5fdd82
                               at /rustc/625451e376bb2e5283fc4741caa0a3e8a2ca4d54/src/libcore/slice/mod.rs:2576
  13:     0x55555559f983 - <alloc::vec::Vec<T> as core::ops::index::IndexMut<I>>::index_mut::h38150e6ef0ae3286
                               at /rustc/625451e376bb2e5283fc4741caa0a3e8a2ca4d54/src/liballoc/vec.rs:1803
  14:     0x555555566aaf - ncollide3d::query::algorithms::epa3::EPA<N>::closest_points::h10a8c6a5a3b3d5e7
                               at /home/me/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide3d-0.20.1/src/query/algorithms/epa3.rs:408
  15:     0x5555555639ef - ncollide3d::query::contact::contact_support_map_support_map::contact_support_map_support_map_with_params::hf054da9b12ed13b2
                               at /home/me/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide3d-0.20.1/src/query/contact/contact_support_map_support_map.rs:72
  16:     0x55555557368f - <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::h9c532b85c41141ad
                               at /home/me/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide3d-0.20.1/src/pipeline/narrow_phase/contact_generator/convex_polyhedron_convex_polyhedron_manifold_generator.rs:95
  17:     0x5555555bcb52 - ncollide3d::pipeline::narrow_phase::narrow_phase::NarrowPhase<N,Handle>::update_contact::hf1a7db2698f9ee56
                               at /home/me/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide3d-0.20.1/src/pipeline/narrow_phase/narrow_phase.rs:73
  18:     0x5555555bdd50 - ncollide3d::pipeline::narrow_phase::narrow_phase::NarrowPhase<N,Handle>::update_interaction::h54c765df7188d224
                               at /home/me/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide3d-0.20.1/src/pipeline/narrow_phase/narrow_phase.rs:152
  19:     0x5555555be565 - ncollide3d::pipeline::narrow_phase::narrow_phase::NarrowPhase<N,Handle>::update::ha6ddc4773b728240
                               at /home/me/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide3d-0.20.1/src/pipeline/narrow_phase/narrow_phase.rs:180
  20:     0x55555564e255 - ncollide3d::pipeline::glue::update::perform_narrow_phase::h057f30cb8be09135
                               at /home/me/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide3d-0.20.1/src/pipeline/glue/update.rs:93
  21:     0x55555564e21c - ncollide3d::pipeline::glue::update::perform_all_pipeline::h3fa81fff950f1417
                               at /home/me/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide3d-0.20.1/src/pipeline/glue/update.rs:109
  22:     0x5555555a1cdb - ncollide3d::pipeline::world::CollisionWorld<N,T>::update::hc2d3713b47a99cbe
                               at /home/me/.cargo/registry/src/github.com-1ecc6299db9ec823/ncollide3d-0.20.1/src/pipeline/world.rs:105
  23:     0x5555555642af - ncollide_bug::main::hfc0790fbffefbd02
                               at src/main.rs:24
  24:     0x5555555c6600 - std::rt::lang_start::{{closure}}::h428e54d2bded33b9
                               at /rustc/625451e376bb2e5283fc4741caa0a3e8a2ca4d54/src/libstd/rt.rs:64
  25:     0x55555569fae3 - std::rt::lang_start_internal::{{closure}}::h4e93c1949c7a1955
                               at src/libstd/rt.rs:49
  26:     0x55555569fae3 - std::panicking::try::do_call::h9440ccd4dc467eaa
                               at src/libstd/panicking.rs:296
  27:     0x5555556a1d9a - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:80
  28:     0x5555556a059d - std::panicking::try::hc046e7ee42ee744f
                               at src/libstd/panicking.rs:275
  29:     0x5555556a059d - std::panic::catch_unwind::h27dfc457c200aee0
                               at src/libstd/panic.rs:394
  30:     0x5555556a059d - std::rt::lang_start_internal::hea1b49a567afe309
                               at src/libstd/rt.rs:48
  31:     0x5555555c65d9 - std::rt::lang_start::h84cf55c96701a481
                               at /rustc/625451e376bb2e5283fc4741caa0a3e8a2ca4d54/src/libstd/rt.rs:64

Below are the crates I use:

approx   = "0.3.2"
alga     = "0.9.1"
nalgebra = "0.18.1"
ncollide3d = "0.20.1"

rustc 1.38.0 (625451e37 2019-09-23)

Here's an OBJ file made out of these triangles.

o Triangles
v 6.292823 6.456138 19.66036
v 6.280472 6.421245 19.57066
v 6.275294 6.449808 19.57066
v 6.292823 6.456138 19.66036
v 6.299445 6.421245 19.66036
v 6.280472 6.421245 19.57066

s off
f 1 2 3
f 4 5 6
@sebcrozet sebcrozet added bug P-medium Medium priority labels Oct 15, 2019
@sebcrozet
Copy link
Member

This looks like an error due to numerical issues, since your triangles are quite small. Thank you for the repro, this will significantly help debugging.

@wlinna
Copy link
Author

wlinna commented Jun 3, 2020

I just updated Cargo.toml to the following

approx   = "0.3.2"
nalgebra = "0.21.0"
ncollide3d = "0.23.0"

and the crash doesn't occur anymore 🎉. Whatever you did, thank you!

I suppose I can close the issue now.

@wlinna wlinna closed this as completed Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug P-medium Medium priority
Projects
None yet
Development

No branches or pull requests

2 participants