diff --git a/crates/effects/src/stroke/dash.rs b/crates/effects/src/stroke/dash.rs index 79676fd443..9388f00b79 100644 --- a/crates/effects/src/stroke/dash.rs +++ b/crates/effects/src/stroke/dash.rs @@ -102,7 +102,9 @@ pub fn dash_kept(bp: &BezPath, d: &Dash, keep: &dyn Fn(&PathSeg) -> bool) -> Opt // so entries that fit down to nothing can't keep a subpath looping. let mut budget = MAX_STEPS as usize; for plan in &plans { - if !dash_subpath(&mut out, plan, &pat, phase, keep, &mut budget) { + // The walk budget counts entries crossed; this counts what they produce, so a pattern of + // many dots can't grow the output past the limit on dashes. + if !dash_subpath(&mut out, plan, &pat, phase, keep, &mut budget) || (out.spans.len() + out.dots.len()) as f64 > MAX_DASHES { return None; } } diff --git a/crates/effects/src/stroke/tests_fit.rs b/crates/effects/src/stroke/tests_fit.rs index 7e983a3a36..d4fb3ec73a 100644 --- a/crates/effects/src/stroke/tests_fit.rs +++ b/crates/effects/src/stroke/tests_fit.rs @@ -249,3 +249,18 @@ fn many_short_subpaths_inside_one_gap_are_not_drawn_solid() { let out = dash(&b, &d).expect("drawn dashed, not solid"); assert!(out.spans.is_empty() && out.dots.is_empty()); } + +#[test] +fn a_pattern_of_many_dots_over_many_subpaths_draws_solid_once_the_dashes_pass_the_limit() { + // Alternating zero-length and tiny entries make a dot per pair on every subpath: far more + // than MAX_DASHES in all, although the walk stays within its budget. + let mut pattern: Vec = (0..2_500).map(|i| if i % 2 == 0 { 0.0 } else { 0.000002 }).collect(); + pattern.extend(vec![1_000_000.0; 2_500]); + let mut b = BezPath::new(); + for i in 0..4_001 { + b.move_to((i as f64 * 2.0, 0.0)); + b.line_to((i as f64 * 2.0 + 1.0, 0.0)); + } + let d = Dash { pattern, offset: 0.0, align_corners: false }; + assert!(dash(&b, &d).is_none()); +}