iced-rs/iced · error

Fill rectangle

Error message

Fill rectangle

What it means

`Geometry::fill_rectangle` tessellates an axis-aligned rectangle with `fill_tessellator.tessellate_rectangle` and `.expect("Fill rectangle")` panics on failure. Rectangle tessellation errors indicate bad numeric inputs (NaN/infinite corners) or an internal vertex allocation failure.

Solutions

  1. Validate `top_left` and `size` for finiteness and positivity before calling `fill_rectangle`.
  2. Clamp computed rectangle geometry to sane bounds in the widget that produces it.
  3. Avoid passing zero-width/zero-height rectangles; skip drawing when the size is degenerate.
  4. If it occurs with valid input, file a bug with iced/lyon including the exact rectangle values.

Example fix

// before
frame.fill_rectangle(position, size);
// after
if size.width.is_finite() && size.height.is_finite() && size.width > 0.0 && size.height > 0.0 {
    frame.fill_rectangle(position, size);
}
Defensive patterns

Strategy: validation

Validate before calling

fn rect_is_valid(top_left: iced::Point, size: iced::Size) -> bool {
    top_left.x.is_finite()
        && top_left.y.is_finite()
        && size.width.is_finite()
        && size.height.is_finite()
        && size.width > 0.0
        && size.height > 0.0
}

Type guard

fn drawable_size(size: iced::Size) -> bool {
    size.width.is_finite() && size.height.is_finite() && size.width > 0.0 && size.height > 0.0
}

Try / catch

// Skip invalid rectangles instead of panicking inside the tessellator
if drawable_size(size) {
    frame.fill_rectangle(position, size);
}

Prevention

When it happens

Trigger: `Frame::fill_rectangle(top_left, size)` (or internal fill calls) where `top_left + size` yields non-finite coordinates, or the lyon tessellator errors for degenerate rectangles; also triggered on GPU buffer allocation failure while writing the output buffer.

Common situations: Computed rectangle positions/sizes containing NaN (layout math divided by zero width); enormous sizes overflowing f32; degenerate zero-area rectangles produced by downstream widgets; faulty custom widget geometry code.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of iced-rs/iced@d146509d89 (2026-09-11). Data as JSON: /api/errors/2952afb6b70f7f59. Report an issue: GitHub.

Appendix: source

Thrown at wgpu/src/geometry.rs:197

            .current
            .0
            .transform_point(lyon::math::Point::new(top_left.x, top_left.y));

        let size = self
            .transforms
            .current
            .0
            .transform_vector(lyon::math::Vector::new(size.width, size.height));

        let options = tessellation::FillOptions::default().with_fill_rule(into_fill_rule(rule));

        self.fill_tessellator
            .tessellate_rectangle(
                &lyon::math::Box2D::new(top_left, top_left + size),
                &options,
                buffer.as_mut(),
            )
            .expect("Fill rectangle");
    }

    fn stroke<'a>(&mut self, path: &Path, stroke: impl Into<Stroke<'a>>) {
        let stroke = stroke.into();

        let mut buffer = self
            .buffers
            .get_stroke(&self.transforms.current.transform_style(stroke.style));

        let mut options = tessellation::StrokeOptions::default();
        options.line_width = stroke.width;
        options.start_cap = into_line_cap(stroke.line_cap);
        options.end_cap = into_line_cap(stroke.line_cap);
        options.line_join = into_line_join(stroke.line_join);

        let path = if stroke.line_dash.segments.is_empty() {
            Cow::Borrowed(path)
        } else {

View on GitHub (pinned to d146509d89)