diff --git a/crates/compose/src/eval.rs b/crates/compose/src/eval.rs index 0815124d..16bf2bd3 100644 --- a/crates/compose/src/eval.rs +++ b/crates/compose/src/eval.rs @@ -1700,6 +1700,12 @@ pub fn composite_tiles_cached(inp: &Inputs, out: &mut Composite, tiles: &[(u32, let holds = below.is_some() && inp.preview.is_none() && has_neighbourhood(inp, &set.stack); let key = if holds { StackKey::new(inp.project, inp.pixels, inp.baked, inp.images, inp.ts, &set.stack).map(Arc::new) } else { None }; let size = (inp.gbuf.width, inp.gbuf.height); + // Fields kept before a stroke began are not used under it, nor held while it lasts + if key.is_none() + && let Some(cache) = below.as_deref_mut() + { + cache.held = None; + } for (at, block) in &blocks { let lacks = |tile: &(u32, u32)| below.as_deref().zip(split.as_deref()).is_none_or(|(cache, _)| cache.tile(*tile).is_none()); let fresh: Vec<(u32, u32)> = block.iter().copied().filter(lacks).collect(); diff --git a/crates/compose/tests/cache_and_instances.rs b/crates/compose/tests/cache_and_instances.rs index bd8efe80..b5dd0602 100644 --- a/crates/compose/tests/cache_and_instances.rs +++ b/crates/compose/tests/cache_and_instances.rs @@ -706,3 +706,28 @@ fn tiles_the_cache_drops_during_a_kept_run_are_filtered_again() { assert!(above.len() > bottom.len()); assert!(out == want, "a tile dropped from the cache was composited with fields that lack the layers off the hot path"); } + +/// A stroke that starts while fields are kept must not leave them allocated for as long as it lasts, even though tiles still follow. +#[test] +fn a_live_stroke_releases_the_fields_kept_before_it_started() { + let mut f = fixture(); + let top = heavy_stack(&mut f); + let all = all_tiles(RES, RES); + let (first, rest) = all.split_at(3); + let mut cache = BelowCache::default(); + cache.set_hot(Some(top)); + + cache.ahead = rest.to_vec(); + run(&f, 0, first, Some(&mut cache)); + assert!(cache.holds_fields()); + + // The stroke begins with tiles still following: the pass is not over, so nothing else would clear them + let preview = stroke(top); + let mut live = run_with(&f, 0, first, Some(&mut cache), Some(&preview)); + assert!(!cache.holds_fields(), "fields kept before the stroke stay allocated while it lasts"); + let (images, baked) = (Default::default(), Default::default()); + let mut inp = inputs(&f, 0, &images, &baked); + inp.preview = Some(&preview); + composite_tiles_cached(&inp, &mut live, rest, Some(&mut cache)); + assert!(live == run_with(&f, 0, &all, None, Some(&preview)), "a stroke that starts during a sliced pass differs"); +}