dimforge / ncollide

2 and 3-dimensional collision detection library in Rust.
https://ncollide.org
Apache License 2.0
921 stars 107 forks source link

Endless loop issue in nonlinear_time_of_impact_support_map_support_map #369

Open Sroka opened 3 years ago

Sroka commented 3 years ago

Hey guys, did anyone ever have had problems with query::nonlinear_time_of_impact hanging and never returning? I am able to reproduce it for two Cuboids with simple ConstantLinearVelocityRigidMotion. I dug into it a bit and it seems that the loop in nonlinear_time_of_impact_support_map_support_map_with_closest_points_function never gets broken out of. In my test case this happens when two cuboids travel in the same direction with the same speed so that they will never meet. This constantly triggers this branch of if-else condition in the loop:

                    } else if dist > max_target_distance {
                        // Too far apart, go forward in time.
                        min_t = result.toi;
                        result.toi = (result.toi + max_t) * _0_5;
                    } else {

which was supposed to increase min_t until it reached required threshold few lines below:

                    if max_t - min_t < abs_tol {
                        result.toi = min_t;
                        break;
                    }

Unfortunately at some point (result.toi + max_t) * _0_5 stops increasing and it converges to a a value that is lower then max_t - abs_tol