a-b-street/abstreet · error

Unsupported color style

Error message

Unsupported color style {:?}

What it means

convert_color panics when an SVG paint uses a color style widgetry does not support. Fill/stroke paints other than solid RGBA and linear gradients (e.g. radial gradients, patterns) hit the catch-all arm and panic.

Solutions

  1. Edit the SVG to replace radial gradients/patterns with solid colors or linear gradients.
  2. Pre-rasterize the SVG to PNG and draw it as a texture instead of parsing vectors.
  3. Run the SVG through a flattening tool (e.g. Inkscape) that converts unsupported paints to solid colors.

Example fix

// before
<radialGradient id="g">...</radialGradient><circle fill="url(#g)"/>
// after
<circle fill="#4a90d9"/>
Defensive patterns

Strategy: validation

Validate before calling

// Reject unsupported paints before loading
if svg_text.contains("radialGradient") || svg_text.contains("<pattern") {
    panic!("{} uses unsupported paint styles", path);
}

Try / catch

// Pre-convert in a build step; at runtime prefer preprocessing over catch (panic is not catchable without catch_unwind).

Prevention

When it happens

Trigger: Loading an SVG whose fill or stroke is a radialGradient, a pattern reference, a context-paint, or any usvg::Paint variant other than Color and LinearGradient, via load_svg/load_svg_bytes or convert_stroke.

Common situations: SVGs exported from design tools (Figma/Illustrator) with radial gradient fills or pattern textures; icons using gradient meshes; auto-generated SVGs with <pattern> backgrounds.

Related errors


AI-assisted analysis of a-b-street/abstreet@0964f29315 (2026-09-13). Data as JSON: /api/errors/0858c3ab3fca9eb5. Report an issue: GitHub.

Appendix: source

Thrown at widgetry/src/svg.rs:178

    let opt = tessellation::StrokeOptions::tolerance(tolerance)
        .with_line_width(s.width.get() as f32)
        .with_line_cap(linecap)
        .with_line_join(linejoin);

    (color, opt)
}

fn convert_color(paint: &usvg::Paint, opacity: f64) -> Fill {
    match paint {
        usvg::Paint::Color(c) => Fill::Color(Color::rgba(
            c.red as usize,
            c.green as usize,
            c.blue as usize,
            opacity as f32,
        )),
        usvg::Paint::LinearGradient(lg) => LinearGradient::new_fill(lg),
        // No patterns or radial gradiants
        _ => panic!("Unsupported color style {:?}", paint),
    }
}

View on GitHub (pinned to 0964f29315)