nalgebra icon indicating copy to clipboard operation
nalgebra copied to clipboard

Infinite loop on pooly defined matrix in UnitQuaternion::from_matrix.

Open lasdasdas opened this issue 6 months ago • 1 comments

This snippet manages to get the execution stuck when running. I know that the values are bad, but also an infinite loop might not be the most desirable outcome of this.

    fn infitite_loop() {
        let mut rot = na::SMatrix::<f64, 3,3>::zeros();
        rot.fill(f64::NAN);
        let _q = UnitQuaternion::from_matrix(&rot);
    }

If the behavior is intended, apologies then.

lasdasdas avatar Jun 27 '25 16:06 lasdasdas

I found the issue causing this

file:/nalgebra/src/geometry/rotation_specialization.rs Image

Upon finding max_iter as 0 we are setting it to the usize::MAX which make it loop forever, but it was alright as we had a breaking machanism for the loop: norm_squared <= new_norm_squared

Image

But this mechanism also fails when NaN values are used. Please help me solve this problem as i'm new to Rust🦀 and Open Source.

PushkarOnGithub avatar Jul 08 '25 18:07 PushkarOnGithub