emilk/egui · error

axis must be 0 or 1, got {axis}

Error message

axis must be 0 or 1, got {axis}

What it means

Error "axis must be 0 or 1, got {axis}" thrown in emilk/egui.

Source

Thrown at crates/emath/src/rect.rs:490

    }

    #[inline(always)]
    pub fn y_range(&self) -> Rangef {
        Rangef::new(self.min.y, self.max.y)
    }

    /// The extent along the given axis: `0` for x, `1` for y.
    ///
    /// Equivalent to [`Self::x_range`] for `axis == 0` and [`Self::y_range`] for `axis == 1`.
    ///
    /// # Panics
    /// If `axis` is not `0` or `1`.
    #[inline]
    pub fn range_along(&self, axis: usize) -> Rangef {
        match axis {
            0 => self.x_range(),
            1 => self.y_range(),
            _ => panic!("axis must be 0 or 1, got {axis}"),
        }
    }

    /// The size along the given axis: `0` for x (width), `1` for y (height).
    ///
    /// Equivalent to `self.size()[axis]`.
    ///
    /// # Panics
    /// If `axis` is not `0` or `1`.
    #[inline]
    pub fn size_along(&self, axis: usize) -> f32 {
        self.size()[axis]
    }

    #[inline(always)]
    pub fn bottom_up_range(&self) -> Rangef {
        Rangef::new(self.max.y, self.min.y)
    }

View on GitHub (pinned to b9a0723d88)

Solutions

  1. Pass only 0 (horizontal/x) or 1 (vertical/y) as the axis argument.

Example fix

let len = if horizontal { rect.width() } else { rect.height() };

When it happens

Trigger: Thrown at crates/emath/src/rect.rs:490 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of emilk/egui@b9a0723d88 (2026-08-19). Data as JSON: /api/errors/ec360042dbabfc3a. Report an issue: GitHub.