bevyengine/bevy · error · AspectRatioError
AspectRatio error: width or height is infinite
Error message
AspectRatio error: width or height is infinite
What it means
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.
Source
Thrown at crates/bevy_math/src/aspect_ratio.rs:98
}
impl TryFrom<Vec2> for AspectRatio {
type Error = AspectRatioError;
#[inline]
fn try_from(value: Vec2) -> Result<Self, Self::Error> {
Self::try_new(value.x, value.y)
}
}
/// An Error type for when [`AspectRatio`](`super::AspectRatio`) is provided invalid width or height values
#[derive(Error, Debug, PartialEq, Eq, Clone, Copy)]
pub enum AspectRatioError {
/// Error due to width or height having zero as a value.
#[error("AspectRatio error: width or height is zero")]
Zero,
/// Error due towidth or height being infinite.
#[error("AspectRatio error: width or height is infinite")]
Infinite,
/// Error due to width or height being Not a Number (NaN).
#[error("AspectRatio error: width or height is NaN")]
NaN,
}
View on GitHub (pinned to 396ca72708)
Solutions
- Reject or sanitize infinite dimensions before constructing AspectRatio
- Fall back to a default finite size when the input extent is infinite
Example fix
// before let ar = AspectRatio::try_new(w, h)?; // h is INFINITY from layout -> Infinite // after let (w, h) = (w.min(8192.0), h.min(8192.0)); let ar = AspectRatio::try_new(w, h)?;
Defensive patterns
Strategy: type-guard
Validate before calling
fn finite_dimensions(w: f32, h: f32) -> bool {
w.is_finite() && h.is_finite()
}
let ar = if finite_dimensions(w, h) {
AspectRatio::try_new(w, h).ok()
} else {
None
}; Try / catch
match AspectRatio::try_new(w, h) {
Ok(ar) => { /* use ar */ }
Err(AspectRatioError::Infinite) => { /* clamp/recompute the dimension source */ }
Err(e) => warn!("bad aspect ratio inputs: {e}"),
} Prevention
- 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.
When it happens
Trigger: Passing dimensions computed from unbounded layout constraints (flex max-size infinity), f32 overflow, or explicit INFINITY sentinels used as 'unset' markers.
Common situations: Using f32::INFINITY as a placeholder for missing sizes; layout code that propagates infinity from grow constraints; projection or camera math with unbounded extents.
Related errors
- AspectRatio error: width or height is NaN
- AspectRatio error: width or height is zero
- Unable to generate cubic curve: at least one set of control
- Wrong number of knots: expected {expected}, provided {provid
- ParamSet parameter validation failed: {err}
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/89bb7ec98d869097.
Report an issue: GitHub.