{"record":{"id":"d2a578fde9305f64","repo":"bevyengine/bevy","slug":"aspectratio-error-width-or-height-is-nan","errorCode":null,"errorMessage":"AspectRatio error: width or height is NaN","messagePattern":"AspectRatio error: width or height is NaN","errorType":"exception","errorClass":"AspectRatioError","httpStatus":null,"severity":"error","filePath":"crates/bevy_math/src/aspect_ratio.rs","lineNumber":101,"sourceCode":"    type Error = AspectRatioError;\n\n    #[inline]\n    fn try_from(value: Vec2) -> Result<Self, Self::Error> {\n        Self::try_new(value.x, value.y)\n    }\n}\n\n/// An Error type for when [`AspectRatio`](`super::AspectRatio`) is provided invalid width or height values\n#[derive(Error, Debug, PartialEq, Eq, Clone, Copy)]\npub enum AspectRatioError {\n    /// Error due to width or height having zero as a value.\n    #[error(\"AspectRatio error: width or height is zero\")]\n    Zero,\n    /// Error due towidth or height being infinite.\n    #[error(\"AspectRatio error: width or height is infinite\")]\n    Infinite,\n    /// Error due to width or height being Not a Number (NaN).\n    #[error(\"AspectRatio error: width or height is NaN\")]\n    NaN,\n}\n","sourceCodeStart":83,"sourceCodeEnd":104,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_math/src/aspect_ratio.rs#L83-L104","documentation":"The same AspectRatio constructors reject NaN width or height (aspect_ratio.rs:40). NaN typically arises from 0.0/0.0-style computations and would silently corrupt the stored ratio, so it is rejected up front.","triggerScenarios":"Passing dimensions produced by 0.0/0.0 math, uninitialized f32 values, or config/serde input that deserialized NaN.","commonSituations":"Degenerate transforms feeding size computations; parsing user config with bad numbers; arithmetic on uninitialized memory patterns after refactors.","solutions":["Trace and fix the upstream 0/0 or otherwise invalid computation.","Check is_nan() at data boundaries (parse, deserialize) and reject or default early.","Add unit tests for size math with degenerate inputs."],"exampleFix":"// before\nlet ar = AspectRatio::try_new(w / total, h / total)?; // NaN when total == 0.0\n\n// after\nif total == 0.0 {\n    return; // no measurable size yet\n}\nlet ar = AspectRatio::try_new(w / total, h / total)?;","handlingStrategy":"validation","validationCode":"fn valid_float_dimensions(w: f32, h: f32) -> bool {\n    w.is_finite() && h.is_finite() && w != 0.0 && h != 0.0 && !w.is_nan() && !h.is_nan()\n}","typeGuard":null,"tryCatchPattern":"match AspectRatio::try_new(w, h) {\n    Ok(ar) => { /* use ar */ }\n    Err(AspectRatioError::NaN) => { /* trace the 0/0 source, skip this frame */ }\n    Err(e) => warn!(\"bad aspect ratio inputs: {e}\"),\n}","preventionTips":["Guard divisions before computing dimensions (check denominators).","Validate deserialized numbers and reject NaN at load time.","Unit-test size math with degenerate inputs (0 sizes, empty totals)."],"tags":["bevy","math","aspect-ratio","validation","nan","float"],"backgroundTag":"nan-value-argument","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}