Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix index out of bounds. #310

Open
Johannes0021 opened this issue Jan 29, 2025 · 0 comments
Open

Matrix index out of bounds. #310

Johannes0021 opened this issue Jan 29, 2025 · 0 comments

Comments

@Johannes0021
Copy link

// Error / Panic --------------------------------------------------------------

parry2d-f64-0.18.0/src/query/clip/clip_aabb_line.rs:141:19:
Matrix index out of bounds.

// What happened ---------------------------------------------------------

I accidentally created a triangle ColliderShape with:

point_a -> Vec2 { data: [40.0, 0.0] }
point_b -> Vec2 { data: [ 0.0, 80.0] } // Same as point_c
point_c -> Vec2 { data: [ 0.0, 80.0] } // Same as point_b

In clip_aabb_line.rs the origin parameter has NAN values -> pub fn clip_aabb_line(...);

In the loop in the else part:
let mut inter_with_near_halfspace = (aabb.mins[i] - origin[i]) * denom; // Results in NaN (origin[i] == NaN)
let mut inter_with_far_halfspace = (aabb.maxs[i] - origin[i]) * denom; // Results in NaN (origin[i] == NaN)

near_diag stays false
near_side stays 0

in line 141 [0 - 1] Matrix index out of bounds.

// Solution ----------------------------------------------------------------

let near = if near_diag {
    (tmin, -dir.normalize(), near_side)
} else {
    let mut normal = Vector::zeros();

    if near_side < 0 {
        normal[(-near_side - 1) as usize] = 1.0;
    } else if near_side > 0 { // <-------------------------------------- Here
        normal[(near_side - 1) as usize] = -1.0;
    }
    else { // <--------------------------------------------------------- Here
        return None;
    }

    (tmin, normal, near_side)
};

let far = if far_diag {
    (tmax, -dir.normalize(), far_side)
} else {
    let mut normal = Vector::zeros();

    if far_side < 0 {
        normal[(-far_side - 1) as usize] = -1.0;
    } else if far_side > 0 { // <--------------------------------------- Here
        normal[(far_side - 1) as usize] = 1.0;
    }
    else { // <--------------------------------------------------------- Here
        return None;
    }

    (tmax, normal, far_side)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant