zed-industries/zed · error

Canvas text raster exceeds maximum dimension

Error message

Canvas text raster exceeds maximum dimension {MAX_RASTER_DIMENSION}: {width}x{height}

What it means

`rasterize` limits each raster dimension to MAX_RASTER_DIMENSION (4096 device pixels) per axis. This error is thrown when the requested bounds width or height exceeds that cap. The guard prevents allocating an absurdly large canvas, which would fail or exhaust memory in browsers (browsers themselves cap canvas dimensions).

Solutions

  1. Split the text into smaller runs so each rasterize call stays within 4096x4096 device pixels.
  2. Reduce the font size or the device scale factor producing oversized bounds.
  3. Fix upstream layout code that computes inflated bounds (check for double application of scale factor).
  4. If bounds are legitimately large, tile the rendering into multiple rasters each within the limit.

Example fix

// before
let bounds = Bounds { origin, size: size(LayoutPixels(6000) * scale) };
rasterize(text, font, bounds, offset, false)?;
// after
for chunk_bounds in split_bounds(bounds, MAX_WIDTH_DEVICE_PX) {
    rasterize(text, font, chunk_bounds, offset, false)?;
}
Defensive patterns

Strategy: validation

Validate before calling

const MAX_RASTER_DIMENSION: u32 = 4096;
if bounds.size.width.0 > MAX_RASTER_DIMENSION || bounds.size.height.0 > MAX_RASTER_DIMENSION {
    // split or shrink before calling
}

Prevention

When it happens

Trigger: Calling `rasterize` with a Bounds<DevicePixels> whose size.width or size.height is > 4096 — e.g. a glyph run spanning an extremely wide line, an enormous font size (huge px font), or a device scale factor that multiplied layout bounds past 4096 device pixels.

Common situations: Rendering at very high DPI/scale factors (layout px * 4x scale exceeding cap); a runaway layout bug producing huge text bounds; rendering a single very long string as one glyph run instead of splitting it.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of zed-industries/zed@916fc2b8cb (2026-09-19). Data as JSON: /api/errors/73821b63a7225ba5. Report an issue: GitHub.

Appendix: source

Thrown at crates/gpui_web/src/canvas_text.rs:135

pub(crate) fn rasterize(
    text: &str,
    css_font: &str,
    bounds: Bounds<DevicePixels>,
    subpixel_offset: (f32, f32),
    color: bool,
) -> Result<Vec<u8>> {
    ensure!(
        subpixel_offset.0.is_finite() && subpixel_offset.1.is_finite(),
        "Canvas text subpixel offset must be finite"
    );
    let width = u32::try_from(bounds.size.width.0)
        .context("Canvas text raster width must be nonnegative")?;
    let height = u32::try_from(bounds.size.height.0)
        .context("Canvas text raster height must be nonnegative")?;
    if width == 0 || height == 0 {
        return Ok(Vec::new());
    }
    ensure!(
        width <= MAX_RASTER_DIMENSION && height <= MAX_RASTER_DIMENSION,
        "Canvas text raster exceeds maximum dimension {MAX_RASTER_DIMENSION}: {width}x{height}"
    );
    let pixel_count = usize::try_from(width)?
        .checked_mul(usize::try_from(height)?)
        .context("Canvas text raster pixel count overflow")?;
    ensure!(
        pixel_count <= MAX_RASTER_PIXELS,
        "Canvas text raster exceeds maximum pixel count {MAX_RASTER_PIXELS}: {width}x{height}"
    );
    let byte_count = pixel_count
        .checked_mul(4)
        .context("Canvas text raster byte count overflow")?;

    with_canvas(|canvas| {
        // Shrink before growing so intermediate canvas sizes obey the pixel cap.
        if height < canvas.canvas.height() {
            canvas.canvas.set_height(height);

View on GitHub (pinned to 916fc2b8cb)