dimforge / parry

2D and 3D collision-detection library for Rust.
https://parry.rs
Apache License 2.0
555 stars 96 forks source link

ColliderShape::convex_decomposition can panic if VHACD generates an empty mesh #50

Open willcrichton opened 3 years ago

willcrichton commented 3 years ago

I'm running convex decomposition on this model: model.tar.gz

I get the following panic:

thread 'main' panicked at 'attempt to subtract with overflow', /Users/will/.cargo/registry/src/github.com-1ecc6299db9ec823/parry3d-0.5.1/src/shape/convex_polyhedron.rs:119:22
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: parry3d::shape::convex_polyhedron::ConvexPolyhedron::from_convex_mesh
             at /Users/will/.cargo/registry/src/github.com-1ecc6299db9ec823/parry3d-0.5.1/src/shape/convex_polyhedron.rs:119:22
   4: parry3d::shape::shared_shape::SharedShape::convex_mesh
             at /Users/will/.cargo/registry/src/github.com-1ecc6299db9ec823/parry3d-0.5.1/src/shape/shared_shape.rs:269:9
   5: parry3d::shape::shared_shape::SharedShape::convex_decomposition_with_params
             at /Users/will/.cargo/registry/src/github.com-1ecc6299db9ec823/parry3d-0.5.1/src/shape/shared_shape.rs:212:35
   6: parry3d::shape::shared_shape::SharedShape::convex_decomposition
             at /Users/will/.cargo/registry/src/github.com-1ecc6299db9ec823/parry3d-0.5.1/src/shape/shared_shape.rs:175:9
   7: preprocess_model::after_spawn
             at ./src/bin/preprocess-model/main.rs:58:18

This happens because a convex hull passed to SharedShape::convex_mesh has fewer than 2 total vertices and indices (presumably empty).