dimforge / rapier

2D and 3D physics engines focused on performance.
https://rapier.rs
Apache License 2.0
3.99k stars 249 forks source link

Narrow phase incorrect incremental state update upon collider reparenting #734

Open hpmv opened 3 weeks ago

hpmv commented 3 weeks ago

When reparenting a collider to another rigidbody, the narrow phase code does not handle the reparenting correctly:

To reproduce (sorry don't have time to write a test case right now but here's exactly what to do):

To fix, we should handle collider parent change correctly in handle_user_changes_on_colliders in narrow_phase.rs, but I'm not sure if this can tackle the first issue, because when the pair was rejected earlier, narrow phase does not know of the pair. The second case can be correctly tackled this way by removing the pair that is no longer supposed to be in the graphs. But there may be other implications of parent change that I'm not aware of.

As a workaround, instead of reparenting I am removing and re-adding the same collider. This solves both issues.

Vrixyz commented 2 weeks ago

Thanks for the detailed reproduction steps, I'm reproducing both scenarios in https://github.com/dimforge/rapier/pull/742