{"record":{"id":"f6d0f467f4ebffec","repo":"zed-industries/zed","slug":"canvas-text-raster-exceeds-maximum-pixel-count-max-raster","errorCode":null,"errorMessage":"Canvas text raster exceeds maximum pixel count {MAX_RASTER_PIXELS}: {width}x{height}","messagePattern":"Canvas text raster exceeds maximum pixel count (.+?): (.+?)x(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui_web/src/canvas_text.rs","lineNumber":142,"sourceCode":"    ensure!(\n        subpixel_offset.0.is_finite() && subpixel_offset.1.is_finite(),\n        \"Canvas text subpixel offset must be finite\"\n    );\n    let width = u32::try_from(bounds.size.width.0)\n        .context(\"Canvas text raster width must be nonnegative\")?;\n    let height = u32::try_from(bounds.size.height.0)\n        .context(\"Canvas text raster height must be nonnegative\")?;\n    if width == 0 || height == 0 {\n        return Ok(Vec::new());\n    }\n    ensure!(\n        width <= MAX_RASTER_DIMENSION && height <= MAX_RASTER_DIMENSION,\n        \"Canvas text raster exceeds maximum dimension {MAX_RASTER_DIMENSION}: {width}x{height}\"\n    );\n    let pixel_count = usize::try_from(width)?\n        .checked_mul(usize::try_from(height)?)\n        .context(\"Canvas text raster pixel count overflow\")?;\n    ensure!(\n        pixel_count <= MAX_RASTER_PIXELS,\n        \"Canvas text raster exceeds maximum pixel count {MAX_RASTER_PIXELS}: {width}x{height}\"\n    );\n    let byte_count = pixel_count\n        .checked_mul(4)\n        .context(\"Canvas text raster byte count overflow\")?;\n\n    with_canvas(|canvas| {\n        // Shrink before growing so intermediate canvas sizes obey the pixel cap.\n        if height < canvas.canvas.height() {\n            canvas.canvas.set_height(height);\n        }\n        if canvas.canvas.width() != width {\n            canvas.canvas.set_width(width);\n        }\n        if canvas.canvas.height() != height {\n            canvas.canvas.set_height(height);\n        }","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/crates/gpui_web/src/canvas_text.rs#L124-L160","documentation":"Beyond per-axis limits, `rasterize` caps total pixel count at MAX_RASTER_PIXELS (4 * 1024 * 1024, i.e. 4M pixels ≈ 16MB RGBA). This error is thrown when width * height exceeds that budget even though each dimension is within 4096. It protects memory: each raster is read back into a JS Uint8ClampedArray and then into a Rust Vec.","triggerScenarios":"Calling `rasterize` with e.g. 4096x1024+ dimensions totaling more than 4,194,304 pixels — a tall/wide glyph run at high scale factor, or large multi-line text bounds passed as a single rasterize call.","commonSituations":"High-DPI rendering (2x-3x scale) of large text blocks; rendering an entire paragraph area instead of per-line glyph runs; a layout bug producing inflated bounds that individually pass the dimension check but multiply past the pixel cap.","solutions":["Break the text region into smaller rasters (per line or tile) so each stays under ~4M pixels.","Lower the device pixel ratio / scale factor used to compute bounds.","Reduce font size or render fewer lines per rasterize call.","Check upstream bounds computation for incorrect scaling that inflates width*height."],"exampleFix":"// before\nlet bounds = Bounds { size: size(px(4000), px(2000)) * scale(2.0) }; // 8000x4000 clamped to 4096x4000 = >4M px\nrasterize(text, font, bounds, offset, false)?;\n// after\nfor line_bounds in bounds.lines_within(MAX_RASTER_PIXELS) {\n    rasterize(line, font, line_bounds, offset, false)?;\n}","handlingStrategy":"validation","validationCode":"const MAX_RASTER_PIXELS: usize = 4 * 1024 * 1024;\nlet pixels = (bounds.size.width.0 as usize).saturating_mul(bounds.size.height.0 as usize);\nif pixels > MAX_RASTER_PIXELS {\n    // tile the region into multiple rasters\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute width * height budget before rasterizing; keep each call under ~4M pixels.","Rasterize per line rather than per paragraph at high scale factors.","Account for device pixel ratio when estimating raster size."],"tags":["canvas","text-rasterization","wasm","memory-limit"],"backgroundTag":"value-out-of-range","analyzedSha":"916fc2b8cb3a815cbef4a3b40e13081be72036b6","analyzedAt":"2026-09-19T19:09:50.599Z","contentChangedAt":"2026-09-19T19:09:50.599Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}