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

Convex decomposition panics on some inputs #65

Open
hakolao opened this issue Nov 16, 2021 · 1 comment
Open

Convex decomposition panics on some inputs #65

hakolao opened this issue Nov 16, 2021 · 1 comment

Comments

@hakolao
Copy link
Contributor

hakolao commented Nov 16, 2021

The following input panics:

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', .../build/parry2d/../../src/shape/convex_polygon.rs:40:12
    let verts = vec![
     Point::new(0.04296875, -0.021484375),
        Point::new(0.041015625, -0.0234375),
        Point::new(0.0390625, -0.025390625),
        Point::new(0.037109375, -0.02734375),
        Point::new(0.03515625, -0.025390625),
        Point::new(0.033203125, -0.0234375),
        Point::new(0.029296875, -0.0234375),
        Point::new(0.02734375, -0.021484375),
        Point::new(0.029296875, -0.01953125),
        Point::new(0.033203125, -0.01953125),
        Point::new(0.037109375, -0.01953125),
        Point::new(0.041015625, -0.01953125),
        Point::new(0.04296875, -0.021484375),
    ];
    let indices = vec![
        [0, 1],
        [1, 2],
        [2, 3],
        [3, 4],
        [4, 5],
        [5, 6],
        [6, 7],
        [7, 8],
        [8, 9],
        [9, 10],
        [10, 11],
        [11, 12],
    ];
    let shape =
       SharedShape::convex_decomposition_with_params(&verts, &indices, &VHACDParameters {
            resolution: 64,
            ..VHACDParameters::default()
        });

This seems to depend on the resolution, if I use 32 or more than 64 on this specific input, it works. I'd like to use 32 or 64 for speed. It does end up in this panic however occasionally with some inputs.

Investigation:
The decomp.compute_exact_convex_hulls(&vertices, &indices) after decompose outputs some empty vertex vectors and passes them to ConvexPolygon::from_convex_polyline. Which then panics when indexing first normal[0] when checking if first vertex should be removed.

Two fix ideas:

  1. Figure out why compute_exact_convex_hulls outputs empty sets of points, fix that or just filter empty parts out.
  2. Don't allow ConvexPolygon::from_convex_polyline to work on empty vectors... (return early if points.len() == 0.
@hakolao
Copy link
Contributor Author

hakolao commented Nov 17, 2021

I suppose this belongs to rapier instead... Will close.

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