{"record":{"id":"e9898d8fcf5a3a5e","repo":"zed-industries/zed","slug":"canvas-text-subpixel-offset-must-be-finite","errorCode":null,"errorMessage":"Canvas text subpixel offset must be finite","messagePattern":"Canvas text subpixel offset must be finite","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui_web/src/canvas_text.rs","lineNumber":124,"sourceCode":"                metrics.ascent,\n                metrics.descent\n            ]\n            .into_iter()\n            .all(f32::is_finite),\n            \"Canvas returned non-finite text metrics\"\n        );\n        Ok(metrics)\n    })\n}\n\npub(crate) fn rasterize(\n    text: &str,\n    css_font: &str,\n    bounds: Bounds<DevicePixels>,\n    subpixel_offset: (f32, f32),\n    color: bool,\n) -> Result<Vec<u8>> {\n    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!(","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/crates/gpui_web/src/canvas_text.rs#L106-L142","documentation":"gpui_web's `rasterize` draws text onto an OffscreenCanvas at a subpixel offset. This error is thrown before any drawing when either component of `subpixel_offset: (f32, f32)` is NaN or infinite. Offsets derived from broken layout math (e.g. division by zero or propagating non-finite text metrics) would be passed to fill_text and produce garbage output, so the library rejects them eagerly.","triggerScenarios":"Calling `rasterize` with a subpixel_offset containing NaN or +/-inf — typically produced upstream by non-finite text metrics (see error 50), a division by zero in glyph positioning, or uninitialized glyph run state in the platform text shaper.","commonSituations":"Rendering after a font failed to load so layout math produced NaN; very large scale factors causing float overflow to infinity in the text system; a bug in an app-level glyph-position calculation passed straight through to rasterize.","solutions":["Check the origin of the offset values; fix the upstream layout/positioning code that produced NaN or infinity.","Sanitize the offset at the call site: replace non-finite values with 0.0 or clamp before calling rasterize.","Verify fonts loaded correctly; unloaded fonts often lead to NaN positions from missing metrics.","Reduce scale/zoom factors that may overflow f32 when computing glyph positions."],"exampleFix":"// before\nrasterize(text, font, bounds, (position.x, position.y), false)?;\n// after\nlet offset = (if position.x.is_finite() { position.x } else { 0.0 },\n              if position.y.is_finite() { position.y } else { 0.0 });\nrasterize(text, font, bounds, offset, false)?;","handlingStrategy":"validation","validationCode":"if !offset.0.is_finite() || !offset.1.is_finite() {\n    return Err(anyhow!(\"invalid subpixel offset from layout\"));\n}\nrasterize(text, font, bounds, offset, color)?;","typeGuard":"fn finite_offset(offset: (f32, f32)) -> bool {\n    offset.0.is_finite() && offset.1.is_finite()\n}","tryCatchPattern":null,"preventionTips":["Sanitize positions computed from divisions or from potentially-NaN text metrics.","Ensure fonts are loaded before layout/rasterization so positions are finite.","Clamp computed glyph positions to a sane range before rasterizing."],"tags":["canvas","text-rasterization","wasm","non-finite"],"backgroundTag":"invalid-argument-value","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"}