parry icon indicating copy to clipboard operation
parry copied to clipboard

Should convex decomposition return an option or a result?

Open hakolao opened this issue 1 year ago • 1 comments

I ran into

A compound shape must contain at least one shape.

I'm generating lots of convex decomposition colliders like this:

        let contours = self.contours_with_holes_flat(bitmap_to_pixels, simplify_epsilon);
        if contours.len() < 4 {
            return vec![];
        }
        let indices = (0..contours.len() as u32 - 1)
            .map(|i| [i, i + 1])
            .collect::<Vec<[u32; 2]>>();
        let collider = ColliderBuilder::convex_decomposition_with_params(
            &contours,
            &indices,
            &VHACDParameters {
                resolution: 64,
                fill_mode,
                ..Default::default()
            },
        )
        .build();

The assertion in parry2d-0.17.0\src\shape\compound.rs:35:9 causes a panic, and can't do much about it. I don't really know when exactly the function fails to generate a shape, and my attempt to not let too small contours only helps for some other panics...

I would prefer no panics, and let the user handle the issues (Option or Result).

hakolao avatar Sep 06 '24 21:09 hakolao

  • I agree with you, I started working on that at https://github.com/dimforge/parry/pull/348.

ThierryBerger avatar Jun 20 '25 08:06 ThierryBerger