{"record":{"id":"89bb7ec98d869097","repo":"bevyengine/bevy","slug":"aspectratio-error-width-or-height-is-infinite","errorCode":null,"errorMessage":"AspectRatio error: width or height is infinite","messagePattern":"AspectRatio error: width or height is infinite","errorType":"exception","errorClass":"AspectRatioError","httpStatus":null,"severity":"error","filePath":"crates/bevy_math/src/aspect_ratio.rs","lineNumber":98,"sourceCode":"}\n\nimpl TryFrom<Vec2> for AspectRatio {\n    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":80,"sourceCodeEnd":104,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_math/src/aspect_ratio.rs#L80-L104","documentation":"AspectRatioError variant raised by AspectRatio::try_new when either the width or height component of the input is infinite. An infinite dimension makes the ratio mathematically undefined, so construction is rejected; check both input components for finiteness before building an AspectRatio.","triggerScenarios":"Passing dimensions computed from unbounded layout constraints (flex max-size infinity), f32 overflow, or explicit INFINITY sentinels used as 'unset' markers.","commonSituations":"Using f32::INFINITY as a placeholder for missing sizes; layout code that propagates infinity from grow constraints; projection or camera math with unbounded extents.","solutions":["Reject or sanitize infinite dimensions before constructing AspectRatio","Fall back to a default finite size when the input extent is infinite"],"exampleFix":"// before\nlet ar = AspectRatio::try_new(w, h)?; // h is INFINITY from layout -> Infinite\n\n// after\nlet (w, h) = (w.min(8192.0), h.min(8192.0));\nlet ar = AspectRatio::try_new(w, h)?;","handlingStrategy":"type-guard","validationCode":"fn finite_dimensions(w: f32, h: f32) -> bool {\n    w.is_finite() && h.is_finite()\n}\n\nlet ar = if finite_dimensions(w, h) {\n    AspectRatio::try_new(w, h).ok()\n} else {\n    None\n};","typeGuard":null,"tryCatchPattern":"match AspectRatio::try_new(w, h) {\n    Ok(ar) => { /* use ar */ }\n    Err(AspectRatioError::Infinite) => { /* clamp/recompute the dimension source */ }\n    Err(e) => warn!(\"bad aspect ratio inputs: {e}\"),\n}","preventionTips":["Do not use f32::INFINITY as an 'unset' marker for sizes.","Clamp layout-derived sizes to a finite maximum before math.","Assert is_finite() on sizes crossing module boundaries."],"tags":["bevy","math","aspect-ratio","validation","infinity","float"],"backgroundTag":"infinite-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"}