Open hakolao opened 10 months ago
I got this too (in rapier3d after despawning a bunch of things)
In Rapier, this is typically caused by CCD, because that uses nonlinear_time_of_impact
, which in turn uses nonlinear_time_of_impact_support_map_support_map
for most shapes.
I don't have time to look into this too deeply right now, but for others wanting to debug this, here are some of my findings just based on looking at the codebase.
The actual issue here is interesting. The non-linear time of impact query calls closest_points
with a max distance using the maximal real value, i.e. Real::MAX
(or Bounded::max_value()
):
Because the max distance is essentially the largest it can be, the result is expected to never be ClosestPoints::Disjoint
(i.e. non-intersecting and above the max distance). This is why the Disjoint
variant is specified as unreachable, but somehow it is reached regardless, which causes the panic.
This indicates that the closest_points
query seems to be the actual culprit for the crash, as it returns Disjoint
in a case where it should never happen.
Disjoint
One option is that the distance between two objects is somehow Real::INFINITY
for whatever reason. I think this would qualify as larger than Real::MAX
, which could make closest_points
return Disjoint
.
If the closest_points
method uses GJK for the given shape pair (it depends on the shapes), a very likely reason it can return Disjoint
could be that GJK returns NoIntersection
, because closest_points_support_map_support_map
returns Disjoint
in that case:
This either happens if (1) at any moment the minimum bound computed by GJK is larger than the maximum distance (it'd have to be Real::INFINITY
in this case), or if (2) GJK runs out of iterations before converging on a solution.
Finally, if the specific shape pair doesn't use GJK for closest_points
, it could be that its special implementation happens to have a bug that causes it to incorrectly return Disjoint
.
If someone wants to debug this, I would recommend finding what exactly returns Disjoint
by adding logs in the appropriate places, like the "unreachable" match branch and the closest_points
implementations. If it's caused by GJK returning NoIntersection
, adding logs there to see what the shapes and isometries are could be useful.
Note that for me while I previously got the same panic, after updating to parry3d 0.15.1
it is now a logged error instead of a panic:
ERROR log: Closest points not found despite setting the max distance to infinity.
See this comment for my reproduction using bevy_rapier
Yep, it was changed temporarily to log an error instead of panicking in #192 until a proper fix is found
I get
This should not happen. it's rather hard to provide a repro