Coder Social home page Coder Social logo

Entered unreachable code about parry HOT 4 OPEN

hakolao avatar hakolao commented on June 30, 2024 1
Entered unreachable code

from parry.

Comments (4)

Jondolf avatar Jondolf commented on June 30, 2024 1

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 problem

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()):

match dispatcher
.closest_points(&pos12, g1, g2, Bounded::max_value())
.ok()?

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.

Potential reasons for returning 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:

GJKResult::NoIntersection(_) => ClosestPoints::Disjoint,

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.

Debugging

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.

from parry.

Jondolf avatar Jondolf commented on June 30, 2024 1

Yep, it was changed temporarily to log an error instead of panicking in #192 until a proper fix is found

from parry.

HyperCodec avatar HyperCodec commented on June 30, 2024

I got this too (in rapier3d after despawning a bunch of things)

from parry.

paul-hansen avatar paul-hansen commented on June 30, 2024

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

from parry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.