dimforge / parry

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

Ensure convex polygon does not panic due to invalid amount of points #168

Closed hakolao closed 2 months ago

hakolao commented 8 months ago

I'm constantly running into panics, due to

parry2d-0.13.5\src\shape\convex_polygon.rs:185:59:
index out of bounds: the len is 2 but the index is 2

This occurs more often than normally (I assume), because I create compound shapes at runtime after deforming objects into smaller ones.

It should not be possible to create a polygon that has less than 3 points. Also, it should be ensured that no empty points is passed. That fixes another crash where normals[0] indexes points that don't exist.

hakolao commented 7 months ago

Related #65 and #50

caspark commented 5 months ago

Calling Rapier's ColliderBuilder::convex_decomposition_with_params(&vertices, &indices, &VHACDParameters { resolution: x, ..}) with 3-4 vertices all approximately x distance from each other seems to be a pretty reliable way to trigger the underlying issue here in Parry.

sebcrozet commented 2 months ago

Thank you!