From 7c5b0da99b0ea6c3a3202925d22061ea1bdea997 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Wed, 21 Oct 2026 21:37:31 +0530 Subject: [PATCH 01/12] Close, New and Open Project free the closed project's memory `Session::replace_project` (`crates/engine/src/lib.rs`), shared by Close, New, Open and the demo project: - forgets the decoded frames and decoders of the closed project's footage, as well as the new project's (the existing #1070 behaviour); - emits `Event::PurgeCaches` after the swap, so the viewers drop the RAM preview of the closed project. Its comp ids can also collide with the new project's. Cache budgets and LRU order are unchanged; only the release path changes. --- crates/engine/src/lib.rs | 10 +++-- crates/engine/src/tests_menu_cmds.rs | 58 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index cdfc7468e..4d8706bff 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -1160,9 +1160,10 @@ impl Session { self.script_ui.project_epoch = self.script_ui.project_epoch.wrapping_add(1); p.fix_next_id(); upgrade_effects(&mut p); - // The media layer keys decoded frames by path: files of the new project may have changed - // since an earlier project decoded them (#1070). - for it in p.items.values() { + // Let go of what the closed project decoded (frames, decoders, models), and of what the + // new project's files decoded under an earlier project: the media layer keys them by + // path, and the files may have changed since (#1070). + for it in self.project.items.values().chain(p.items.values()) { if let effectcraft_project::ItemKind::Footage(f) = &it.kind { self.forget_decoded(f); } @@ -1174,6 +1175,9 @@ impl Session { self.path = path; self.bump(); self.mark_saved(); + // The viewers' RAM preview shows the closed project's frames, whose comp ids can collide + // with the new project's. + self.events.push(Event::PurgeCaches); let first = self.project.comps().next().map(|(id, _)| *id); if let Some(c) = first { self.open_comp(c); diff --git a/crates/engine/src/tests_menu_cmds.rs b/crates/engine/src/tests_menu_cmds.rs index 6da07dd40..83f3b609c 100644 --- a/crates/engine/src/tests_menu_cmds.rs +++ b/crates/engine/src/tests_menu_cmds.rs @@ -1767,3 +1767,61 @@ fn old_guides_load_as_pixel_guides_and_percent_round_trips() { // A zero-sized comp never divides by zero. assert!(g.px(0, 0).is_finite()); } + +#[test] +fn replacing_project_releases_old_footage() { + // A footage source that records the paths it is told to forget. + struct Recording(std::sync::Mutex>); + impl crate::render::FootageSource for Recording { + fn frame( + &self, + _: effectcraft_project::ItemId, + _: &effectcraft_project::Footage, + _: effectcraft_time::Tick, + ) -> Option> { + None + } + fn forget(&self, path: &str) { + self.0.lock().unwrap().push(path.to_string()); + } + } + let mut s = comp(); + let src = std::sync::Arc::new(Recording(Default::default())); + s.footage = src.clone(); + let recorded = || src.0.lock().unwrap().clone(); + let with_old = |s: &Session| { + let mut p = (*s.project).clone(); + p.add_item("old", Default::default(), None, ItemKind::Footage(effectcraft_project::Footage { path: "/old.mp4".into(), ..Default::default() })); + p + }; + let old = with_old(&s); + s.replace_project(old, None); + s.drain_events(); + src.0.lock().unwrap().clear(); + + // Close Project lets go of the closed project's footage and clears the RAM preview. + s.execute("file.closeProject", json!({})).unwrap(); + assert!(recorded().contains(&"/old.mp4".to_string()), "{:?}", recorded()); + assert!(s.drain_events().contains(&Event::PurgeCaches)); + + // Opening a project forgets the old project's files and the new project's. + let old = with_old(&s); + s.replace_project(old, None); + s.drain_events(); + src.0.lock().unwrap().clear(); + let mut new = effectcraft_project::Project::default(); + new.add_item("new", Default::default(), None, ItemKind::Footage(effectcraft_project::Footage { path: "/new.mp4".into(), ..Default::default() })); + s.replace_project(new, None); + let paths = recorded(); + assert!(paths.contains(&"/old.mp4".to_string()) && paths.contains(&"/new.mp4".to_string()), "{paths:?}"); + assert!(s.drain_events().contains(&Event::PurgeCaches)); + + // New Project does the same. + let old = with_old(&s); + s.replace_project(old, None); + s.drain_events(); + src.0.lock().unwrap().clear(); + s.execute("file.newProject", json!({})).unwrap(); + assert!(recorded().contains(&"/old.mp4".to_string()), "{:?}", recorded()); + assert!(s.drain_events().contains(&Event::PurgeCaches)); +} From 1dcb8273a45ac0bd9a4a3d05f78f53522e00d585 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Wed, 21 Oct 2026 21:47:06 +0530 Subject: [PATCH 02/12] Fast Previews: Adaptive Resolution applies while dragging in the Timeline `timeline::show` keeps a per-frame `dragging` flag. While the primary button is down, it sets the existing `property_interacting` for: - dragging the playhead or the timecode; - moving layer bars, or their in and out points; - dragging keys, and the key alt-scale. A click without movement doesn't set it. The existing clear at the start of each frame handles the release, so the first frame after it is sharp. With Fast Previews off (the default) or a fixed resolution, nothing changes. 9 lines of production code. --- crates/ui-egui/src/panels/timeline.rs | 9 +- crates/ui-egui/src/state.rs | 1 + .../ui-egui/tests/ui_timeline_interacting.rs | 115 ++++++++++++++++++ 3 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 crates/ui-egui/tests/ui_timeline_interacting.rs diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs index b34fbd9d3..1d9703ddb 100644 --- a/crates/ui-egui/src/panels/timeline.rs +++ b/crates/ui-egui/src/panels/timeline.rs @@ -1468,6 +1468,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { p.line_segment([pos2(graph_x0 - 1.0, top), pos2(graph_x0 - 1.0, rect.max.y)], Stroke::new(1.0, t.app_bg)); let mut actions: Vec<(String, serde_json::Value)> = Vec::new(); + let mut dragging = false; // A drag that moves the frame on screen (Fast Previews). if !ui.input(|i| i.pointer.primary_down()) { ctx.data_mut(|d| d.remove::(switch_drag_id())); } @@ -1495,6 +1496,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { app.auto.add("timeline.timecode", tc_rect, &tc); super::toggle_time_display(app, &tc_resp); if tc_resp.dragged() { + dragging = true; let d = tc_resp.drag_delta().x as f64; let f = fr.frame_at(time) + (d * 0.5).round() as i64; let _ = app.session.execute("time.set", json!({"frame": f.max(0)})); @@ -1730,6 +1732,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { if ((rresp.is_pointer_button_down_on() && ui.input(|i| i.pointer.primary_down())) || rresp.clicked()) && let Some(pt) = rresp.interact_pointer_pos() { + dragging |= rresp.dragged(); let mut x = pt.x; // Zoomed in, a scrub held past either end of the ruler scrolls the timeline that way // (faster the further), with the CTI at the edge (After Effects). @@ -2360,6 +2363,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { continue; } if resp.dragged() { + dragging = true; let acc_id = egui::Id::new(("bar-acc", layer.id.0, kind)); let mut acc: f32 = ctx.data(|d| d.get_temp(acc_id).unwrap_or(0.0)); acc += resp.drag_delta().x; @@ -3149,6 +3153,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { let (down, ptr) = ctx.input(|i| (i.pointer.primary_down(), i.pointer.latest_pos())); match ptr.filter(|_| down) { Some(ptr) => { + dragging = true; let frames = (((ptr.x - q.origin_x) as f64 / pps) / fd).round() as i64; if frames != q.applied { q.applied = frames; @@ -3171,6 +3176,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { let (down, ptr, shift) = ctx.input(|i| (i.pointer.primary_down(), i.pointer.latest_pos(), i.modifiers.shift)); match ptr.filter(|_| down) { Some(ptr) => { + dragging = true; let mut target = kd.anchor + (ptr.x - kd.origin_x) as f64 / pps; if shift { // The current time and whatever it snaps to (keys, layer ends, markers), but @@ -3474,7 +3480,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { } } } - if ui.input(|i| i.pointer.primary_down()) && actions.iter().any(|(id, _)| id == "prop.set") { + dragging |= super::graph_tools::alt_scale_active(&ctx); + if ui.input(|i| i.pointer.primary_down()) && (dragging || actions.iter().any(|(id, _)| id == "prop.set")) { app.ui.viewer.property_interacting = true; ctx.request_repaint(); } diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 1e2f57204..206c70cf3 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -264,6 +264,7 @@ pub struct ViewerState { /// The pointer is dragging in the viewer this frame (Adaptive Resolution). #[serde(skip)] pub interacting: bool, + /// A property scrub (Effect Controls, Timeline) or a Timeline drag of the playhead, keys or layer bars is in progress (Adaptive Resolution); cleared once the primary button is up. #[serde(skip)] pub property_interacting: bool, /// Extended Viewer: the comp-space region the viewer renders this frame (comp frame plus diff --git a/crates/ui-egui/tests/ui_timeline_interacting.rs b/crates/ui-egui/tests/ui_timeline_interacting.rs new file mode 100644 index 000000000..29f86b6ff --- /dev/null +++ b/crates/ui-egui/tests/ui_timeline_interacting.rs @@ -0,0 +1,115 @@ +use effectcraft_engine::Session; +use effectcraft_engine::project::LayerId; +use effectcraft_ui_egui::EffectcraftApp; +use egui::{Event, Pos2, pos2, vec2}; +use egui_kittest::Harness; +use serde_json::json; + +fn harness() -> (Harness<'static, EffectcraftApp>, LayerId, u64) { + let mut session = Session::default(); + session.execute("comp.new", json!({"name": "Keys", "width": 320, "height": 180, "frameRate": 30, "duration": 4})).unwrap(); + session.execute("layer.newSolid", json!({"name": "Box", "color": "#e04020", "width": 80, "height": 80})).unwrap(); + let id = session.active_comp().unwrap().layers[0].id; + for (time, value) in [(0.0, 0.0), (1.0, 100.0)] { + session.execute("prop.addKey", json!({"layer": id.0, "path": "transform/opacity", "time": time, "value": value})).unwrap(); + } + let uid = session.active_comp().unwrap().layer(id).unwrap().props.prop("transform/opacity").unwrap().uid; + session.execute("layer.select", json!({"layers": [id.0]})).unwrap(); + session.execute("view.fastPreviewMode", json!({"mode": "adaptive"})).unwrap(); + let mut harness = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(session)); + harness.run_steps(3); + let context = harness.ctx.clone(); + effectcraft_ui_egui::menus::invoke(harness.state_mut(), &context, "timeline.reveal.opacity", json!({})).unwrap(); + harness.run_steps(4); + (harness, id, uid) +} + +fn rect(harness: &Harness<'_, EffectcraftApp>, id: &str) -> egui::Rect { + let entry = harness.state().auto.find(id).expect("timeline element"); + egui::Rect::from_min_size(pos2(entry.rect[0], entry.rect[1]), vec2(entry.rect[2], entry.rect[3])) +} + +fn keys(harness: &Harness<'_, EffectcraftApp>, uid: u64) -> Vec { + let mut positions: Vec = harness + .state() + .auto + .query(&format!("timeline.key.{uid}.")) + .iter() + .map(|entry| pos2(entry.rect[0] + entry.rect[2] / 2.0, entry.rect[1] + entry.rect[3] / 2.0)) + .collect(); + positions.sort_by(|left, right| left.x.total_cmp(&right.x)); + positions +} + +fn hold(harness: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2) { + harness.input_mut().events.push(Event::PointerMoved(from)); + harness.step(); + harness.input_mut().events.push(Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + harness.step(); + for step in 1..=10 { + harness.input_mut().events.push(Event::PointerMoved(from + (to - from) * (step as f32 / 10.0))); + harness.step(); + } +} + +fn release(harness: &mut Harness<'_, EffectcraftApp>, at: Pos2) { + harness.input_mut().events.push(Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); + harness.run_steps(2); +} + +fn assert_adaptive_during_drag(harness: &Harness<'_, EffectcraftApp>) { + assert!(harness.state().ui.viewer.property_interacting); + assert!(harness.state().viewer_scale(1.0, 1.0) < 1.0); +} + +fn assert_full_resolution_after_release(harness: &Harness<'_, EffectcraftApp>) { + assert!(!harness.state().ui.viewer.property_interacting); + assert_eq!(harness.state().viewer_scale(1.0, 1.0), 1.0); +} + +#[test] +fn playhead_drag_uses_adaptive_resolution() { + let (mut harness, _, _) = harness(); + let ruler = rect(&harness, "timeline.ruler"); + let from = pos2(ruler.min.x + 40.0, ruler.max.y - 3.0); + let to = from + vec2(200.0, 0.0); + hold(&mut harness, from, to); + assert_adaptive_during_drag(&harness); + release(&mut harness, to); + assert_full_resolution_after_release(&harness); +} + +#[test] +fn layer_bar_drag_uses_adaptive_resolution() { + let (mut harness, layer, _) = harness(); + let from = rect(&harness, &format!("timeline.layer.{}.bar", layer.0)).center(); + let to = from + vec2(60.0, 0.0); + hold(&mut harness, from, to); + assert_adaptive_during_drag(&harness); + release(&mut harness, to); + assert_full_resolution_after_release(&harness); +} + +#[test] +fn key_drag_uses_adaptive_resolution() { + let (mut harness, _, uid) = harness(); + let from = keys(&harness, uid)[0]; + let to = from + vec2(60.0, 0.0); + hold(&mut harness, from, to); + assert_adaptive_during_drag(&harness); + release(&mut harness, to); + assert_full_resolution_after_release(&harness); +} + +#[test] +fn timeline_click_keeps_full_resolution() { + let (mut harness, _, _) = harness(); + let point = rect(&harness, "timeline.ruler").center(); + harness.input_mut().events.push(Event::PointerMoved(point)); + harness.step(); + harness.input_mut().events.push(Event::PointerButton { pos: point, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + harness.step(); + assert!(!harness.state().ui.viewer.property_interacting); + assert_eq!(harness.state().viewer_scale(1.0, 1.0), 1.0); + release(&mut harness, point); +} From 550aeb0ac9f6d36416109d6b3ccc330b3a8b7028 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:00:04 +0530 Subject: [PATCH 03/12] #2047: tests for Adaptive Resolution during Timeline and Properties drags Drag/release tests for the playhead, timecode, layer bar, In trim, source slip, key drag, the In/Out/Duration cells and a Properties scrub: a draft while held, Full on the first frame after release. A click, a work-area drag (same pixels) and Fast Previews off keep Full. --- .../tests/it/ui_timeline_interacting.rs | 224 ++++++++++++------ 1 file changed, 145 insertions(+), 79 deletions(-) diff --git a/crates/ui-egui/tests/it/ui_timeline_interacting.rs b/crates/ui-egui/tests/it/ui_timeline_interacting.rs index 29f86b6ff..6ed4c719a 100644 --- a/crates/ui-egui/tests/it/ui_timeline_interacting.rs +++ b/crates/ui-egui/tests/it/ui_timeline_interacting.rs @@ -1,115 +1,181 @@ +//! Fast Previews ▸ Adaptive Resolution while dragging outside the viewer (After Effects): any +//! Timeline drag that changes the frame on screen (the time, or the comp's pixels) draws a draft +//! until release, and the first frame after the release is full resolution again. A plain click, +//! or a drag that changes nothing on screen, keeps Full. use effectcraft_engine::Session; -use effectcraft_engine::project::LayerId; use effectcraft_ui_egui::EffectcraftApp; use egui::{Event, Pos2, pos2, vec2}; use egui_kittest::Harness; use serde_json::json; -fn harness() -> (Harness<'static, EffectcraftApp>, LayerId, u64) { - let mut session = Session::default(); - session.execute("comp.new", json!({"name": "Keys", "width": 320, "height": 180, "frameRate": 30, "duration": 4})).unwrap(); - session.execute("layer.newSolid", json!({"name": "Box", "color": "#e04020", "width": 80, "height": 80})).unwrap(); - let id = session.active_comp().unwrap().layers[0].id; +/// The Timeline of a 10 s comp at 30 fps with a solid (opacity keys at 0 s and 1 s, revealed) +/// and a 20 s precomp trimmed to 3–7 s (its source runs past both ends, so it can slip), in +/// Adaptive Resolution. +struct Fixture { + h: Harness<'static, EffectcraftApp>, + solid: u64, + pre: u64, + opacity: u64, +} + +fn fixture(mode: &str) -> Fixture { + let mut s = Session::default(); + s.execute("comp.new", json!({"name": "Inner", "width": 320, "height": 180, "frameRate": 30, "duration": 20})).unwrap(); + s.execute("comp.new", json!({"name": "Main", "width": 320, "height": 180, "frameRate": 30, "duration": 10})).unwrap(); + let solid = s.execute("layer.newSolid", json!({"name": "Box", "color": "#e04020", "width": 80, "height": 80})).unwrap()["layer"].as_u64().unwrap(); for (time, value) in [(0.0, 0.0), (1.0, 100.0)] { - session.execute("prop.addKey", json!({"layer": id.0, "path": "transform/opacity", "time": time, "value": value})).unwrap(); + s.execute("prop.addKey", json!({"layer": solid, "path": "transform/opacity", "time": time, "value": value})).unwrap(); } - let uid = session.active_comp().unwrap().layer(id).unwrap().props.prop("transform/opacity").unwrap().uid; - session.execute("layer.select", json!({"layers": [id.0]})).unwrap(); - session.execute("view.fastPreviewMode", json!({"mode": "adaptive"})).unwrap(); - let mut harness = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(session)); - harness.run_steps(3); - let context = harness.ctx.clone(); - effectcraft_ui_egui::menus::invoke(harness.state_mut(), &context, "timeline.reveal.opacity", json!({})).unwrap(); - harness.run_steps(4); - (harness, id, uid) + let pre = s.execute("layer.addItem", json!({"item": "Inner"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("layer.timing", json!({"layers": [pre], "in": 3.0, "out": 7.0})).unwrap(); + let comp = s.active_comp().unwrap(); + let opacity = comp.layers.iter().find(|l| l.id.0 == solid).unwrap().props.prop("transform/opacity").unwrap().uid; + s.execute("layer.select", json!({"layers": [solid]})).unwrap(); + s.execute("view.fastPreviewMode", json!({"mode": mode})).unwrap(); + let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s)); + h.run_steps(3); + let ctx = h.ctx.clone(); + effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "timeline.reveal.opacity", json!({})).unwrap(); + h.run_steps(4); + Fixture { h, solid, pre, opacity } } -fn rect(harness: &Harness<'_, EffectcraftApp>, id: &str) -> egui::Rect { - let entry = harness.state().auto.find(id).expect("timeline element"); - egui::Rect::from_min_size(pos2(entry.rect[0], entry.rect[1]), vec2(entry.rect[2], entry.rect[3])) +fn rect(h: &Harness<'_, EffectcraftApp>, id: &str) -> egui::Rect { + let e = h.state().auto.find(id).unwrap_or_else(|| panic!("no {id}")); + egui::Rect::from_min_size(pos2(e.rect[0], e.rect[1]), vec2(e.rect[2], e.rect[3])) } -fn keys(harness: &Harness<'_, EffectcraftApp>, uid: u64) -> Vec { - let mut positions: Vec = harness - .state() - .auto - .query(&format!("timeline.key.{uid}.")) - .iter() - .map(|entry| pos2(entry.rect[0] + entry.rect[2] / 2.0, entry.rect[1] + entry.rect[3] / 2.0)) - .collect(); - positions.sort_by(|left, right| left.x.total_cmp(&right.x)); - positions +/// What a frame-changing drag must change: the project or the current time. +fn on_screen(h: &Harness<'_, EffectcraftApp>) -> (u64, effectcraft_time::Tick) { + (h.state().session.revision, h.state().session.time()) } -fn hold(harness: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2) { - harness.input_mut().events.push(Event::PointerMoved(from)); - harness.step(); - harness.input_mut().events.push(Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); - harness.step(); +/// Presses at `from` and moves to `to` in ten steps, leaving the button down. +fn hold(h: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2) { + h.input_mut().events.push(Event::PointerMoved(from)); + h.step(); + h.input_mut().events.push(Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + h.step(); for step in 1..=10 { - harness.input_mut().events.push(Event::PointerMoved(from + (to - from) * (step as f32 / 10.0))); - harness.step(); + h.input_mut().events.push(Event::PointerMoved(from + (to - from) * (step as f32 / 10.0))); + h.step(); } } -fn release(harness: &mut Harness<'_, EffectcraftApp>, at: Pos2) { - harness.input_mut().events.push(Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); - harness.run_steps(2); +/// Releases at `at` and runs exactly one frame: that frame must already be sharp. +fn release(h: &mut Harness<'_, EffectcraftApp>, at: Pos2) { + h.input_mut().events.push(Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); + h.step(); } -fn assert_adaptive_during_drag(harness: &Harness<'_, EffectcraftApp>) { - assert!(harness.state().ui.viewer.property_interacting); - assert!(harness.state().viewer_scale(1.0, 1.0) < 1.0); +fn draft(h: &Harness<'_, EffectcraftApp>) -> bool { + h.state().viewer_scale(1.0, 1.0) < 1.0 } -fn assert_full_resolution_after_release(harness: &Harness<'_, EffectcraftApp>) { - assert!(!harness.state().ui.viewer.property_interacting); - assert_eq!(harness.state().viewer_scale(1.0, 1.0), 1.0); +/// Drags from `from` by `by`: a draft while held, Full on the first frame after release. +fn assert_draft_while_dragging(f: &mut Fixture, from: Pos2, by: egui::Vec2) { + let before = on_screen(&f.h); + hold(&mut f.h, from, from + by); + assert_ne!(on_screen(&f.h), before, "the drag changed nothing on screen"); + assert!(f.h.state().ui.viewer.property_interacting, "not interacting while dragging"); + assert!(draft(&f.h), "full resolution while dragging"); + release(&mut f.h, from + by); + assert!(!f.h.state().ui.viewer.property_interacting, "still interacting after release"); + assert!(!draft(&f.h), "the first frame after release is a draft"); } #[test] -fn playhead_drag_uses_adaptive_resolution() { - let (mut harness, _, _) = harness(); - let ruler = rect(&harness, "timeline.ruler"); - let from = pos2(ruler.min.x + 40.0, ruler.max.y - 3.0); - let to = from + vec2(200.0, 0.0); - hold(&mut harness, from, to); - assert_adaptive_during_drag(&harness); - release(&mut harness, to); - assert_full_resolution_after_release(&harness); +fn playhead_drag_draws_a_draft() { + let mut f = fixture("adaptive"); + let ruler = rect(&f.h, "timeline.ruler"); + assert_draft_while_dragging(&mut f, pos2(ruler.min.x + 40.0, ruler.max.y - 3.0), vec2(200.0, 0.0)); } #[test] -fn layer_bar_drag_uses_adaptive_resolution() { - let (mut harness, layer, _) = harness(); - let from = rect(&harness, &format!("timeline.layer.{}.bar", layer.0)).center(); - let to = from + vec2(60.0, 0.0); - hold(&mut harness, from, to); - assert_adaptive_during_drag(&harness); - release(&mut harness, to); - assert_full_resolution_after_release(&harness); +fn timecode_drag_draws_a_draft() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, "timeline.timecode").center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); } #[test] -fn key_drag_uses_adaptive_resolution() { - let (mut harness, _, uid) = harness(); - let from = keys(&harness, uid)[0]; - let to = from + vec2(60.0, 0.0); - hold(&mut harness, from, to); - assert_adaptive_during_drag(&harness); - release(&mut harness, to); - assert_full_resolution_after_release(&harness); +fn layer_bar_drag_draws_a_draft() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, &format!("timeline.layer.{}.bar", f.solid)).center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); +} + +#[test] +fn in_point_trim_draws_a_draft() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, &format!("timeline.layer.{}.bar.in", f.pre)).center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); +} + +#[test] +fn source_slip_draws_a_draft() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, &format!("timeline.layer.{}.sourcel", f.pre)).center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); +} + +#[test] +fn key_drag_draws_a_draft() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, &format!("timeline.key.{}.0", f.opacity)).center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); +} + +#[test] +fn in_out_and_duration_cell_drags_draw_a_draft() { + for kind in ["in", "out", "duration"] { + let mut f = fixture("adaptive"); + effectcraft_ui_egui::panels::timeline::set_column(&mut f.h.state_mut().ui.timeline, kind, true).unwrap(); + f.h.run_steps(3); + let from = rect(&f.h, &format!("timeline.layer.{}.{kind}", f.pre)).center(); + assert_draft_while_dragging(&mut f, from, vec2(60.0, 0.0)); + } +} + +#[test] +fn properties_scrub_draws_a_draft() { + let mut f = fixture("adaptive"); + let ctx = f.h.ctx.clone(); + effectcraft_ui_egui::menus::invoke(f.h.state_mut(), &ctx, "window.panel", json!({"panel": "properties"})).unwrap(); + f.h.run_steps(3); + let from = rect(&f.h, &format!("properties.prop.{}.value", f.opacity)).center(); + assert_draft_while_dragging(&mut f, from, vec2(40.0, 0.0)); +} + +#[test] +fn work_area_drag_keeps_full_resolution() { + let mut f = fixture("adaptive"); + let from = rect(&f.h, "timeline.workArea.end").center(); + let before = f.h.state().session.active_comp().unwrap().work_area; + hold(&mut f.h, from, from + vec2(-80.0, 0.0)); + assert_ne!(f.h.state().session.active_comp().unwrap().work_area, before, "the work area moved"); + assert!(!draft(&f.h), "a work-area drag changes no pixels"); + release(&mut f.h, from); } #[test] fn timeline_click_keeps_full_resolution() { - let (mut harness, _, _) = harness(); - let point = rect(&harness, "timeline.ruler").center(); - harness.input_mut().events.push(Event::PointerMoved(point)); - harness.step(); - harness.input_mut().events.push(Event::PointerButton { pos: point, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); - harness.step(); - assert!(!harness.state().ui.viewer.property_interacting); - assert_eq!(harness.state().viewer_scale(1.0, 1.0), 1.0); - release(&mut harness, point); + let mut f = fixture("adaptive"); + let point = rect(&f.h, "timeline.ruler").center(); + f.h.input_mut().events.push(Event::PointerMoved(point)); + f.h.step(); + f.h.input_mut().events.push(Event::PointerButton { pos: point, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + f.h.run_steps(3); + assert!(!draft(&f.h)); + release(&mut f.h, point); +} + +#[test] +fn fast_previews_off_keeps_full_resolution() { + let mut f = fixture("off"); + let ruler = rect(&f.h, "timeline.ruler"); + let from = pos2(ruler.min.x + 40.0, ruler.max.y - 3.0); + hold(&mut f.h, from, from + vec2(200.0, 0.0)); + assert!(!draft(&f.h)); + release(&mut f.h, from); } From 724865e3405233eef2db75b9e09bfade30a6c11e Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:00:04 +0530 Subject: [PATCH 04/12] #2047: Fast Previews: any frame-changing Timeline drag draws a draft One rule instead of a flag per gesture: DragWatch snapshots the active comp and its current frame when the Timeline (and the Properties panel) starts its pass, and after the pass, while the primary button drags past a click, a new frame or a comp that no longer draws the same pixels sets property_interacting until release. This covers the playhead and timecode, layer moves and trims, slips, key drags and alt-scale, Quick Offset, the In/Out/Duration cells, property scrubs and the Graph Editor, and any gesture added later. Clicks, scrolling, zooming, the work area and selection keep Full. It replaces the prop.set-only check in apply_actions. --- crates/ui-egui/src/panels.rs | 1 + crates/ui-egui/src/panels/drag_preview.rs | 47 +++++++++++++++++++++++ crates/ui-egui/src/panels/properties.rs | 2 + crates/ui-egui/src/panels/timeline.rs | 10 ++--- crates/ui-egui/src/state.rs | 4 +- 5 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 crates/ui-egui/src/panels/drag_preview.rs diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index ccff0fdcd..8feb8c8c5 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -9,6 +9,7 @@ pub mod crypto_pick; pub mod delete_items; pub mod dialogs; pub mod dialogs_3d; +pub(crate) mod drag_preview; pub mod effect_controls; pub mod effects_presets; pub mod essential; diff --git a/crates/ui-egui/src/panels/drag_preview.rs b/crates/ui-egui/src/panels/drag_preview.rs new file mode 100644 index 000000000..9d0d42f7b --- /dev/null +++ b/crates/ui-egui/src/panels/drag_preview.rs @@ -0,0 +1,47 @@ +//! Fast Previews ▸ Adaptive Resolution for drags outside the viewer: as in After Effects, a drag +//! that changes the frame on screen (scrubbing the time, moving or trimming layers, slipping, +//! dragging keys, scrubbing values) draws a draft until the button is released. + +use std::sync::Arc; + +use effectcraft_engine::project::{Comp, ItemId}; + +use crate::EffectcraftApp; + +/// The frame on screen when a panel starts its pass: the active comp and its current frame. +/// [`DragWatch::end`] compares it with the frame after the panel ran its gestures, so every drag +/// the panel handles is covered without a flag per gesture. +pub(crate) struct DragWatch { + before: Option<(ItemId, Arc, i64)>, +} + +impl DragWatch { + pub(crate) fn begin(app: &EffectcraftApp) -> Self { + let before = app.session.active_comp_id().and_then(|id| { + let comp = app.session.project.comp_arc(id)?; + let frame = comp.frame_rate.frame_at(app.session.time()); + Some((id, comp, frame)) + }); + Self { before } + } + + /// While the primary button drags (moved past a click), a change of the current frame or of + /// the active comp's pixels since [`Self::begin`] sets `property_interacting`, which stays + /// set until the button is up (`App::frame`). A click, a held button, or a drag that draws + /// the same pixels (scrolling, zooming, the work area, selecting) keeps Full. + pub(crate) fn end(self, app: &mut EffectcraftApp, ctx: &egui::Context) { + let Some((id, comp, frame)) = self.before else { return }; + if app.ui.viewer.property_interacting || !ctx.input(|i| i.pointer.primary_down() && i.pointer.is_decidedly_dragging()) { + return; + } + if app.session.active_comp_id() != Some(id) { + return; + } + let Some(now) = app.session.project.comp_arc(id) else { return }; + let moved = comp.frame_rate.frame_at(app.session.time()) != frame; + if moved || (!Arc::ptr_eq(&comp, &now) && !now.same_pixels(&comp)) { + app.ui.viewer.property_interacting = true; + ctx.request_repaint(); + } + } +} diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rs index 4edcbb31a..74ae4daec 100644 --- a/crates/ui-egui/src/panels/properties.rs +++ b/crates/ui-egui/src/panels/properties.rs @@ -67,6 +67,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { p.text(rect.center(), Align2::CENTER_CENTER, crate::i18n::tr("Select a layer to see its properties"), Tokens::ui(12.0), t.text_faint); return; }; + let watch = super::drag_preview::DragWatch::begin(app); let project = app.session.project.clone(); let expr = app.session.expr.clone(); let now = app.session.time(); @@ -190,6 +191,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { app.ui.status = e; } } + watch.end(app, &ctx); } fn section_header(app: &mut EffectcraftApp, p: &egui::Painter, x0: f32, w: f32, y: f32, title: &str, auto: &str) { diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs index 4de3233e8..4d35de005 100644 --- a/crates/ui-egui/src/panels/timeline.rs +++ b/crates/ui-egui/src/panels/timeline.rs @@ -1963,6 +1963,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { return; }; let Some(comp) = app.session.project.comp_arc(cid) else { return }; + let watch = super::drag_preview::DragWatch::begin(app); let mut tl = layout(app, ui, rect, cid, &comp); let g = &mut tl; if !ui.input(|i| i.pointer.primary_down()) { @@ -2022,7 +2023,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { drop_targets(app, ui, g); let Rw { tl, ui_actions, .. } = rw; apply_ui_acts(app, &tl.comp, ui_actions); - apply_actions(app, ui, &tl.ctx, tl.actions); + apply_actions(app, &tl.ctx, tl.actions); + watch.end(app, &tl.ctx); } /// Applies the UI-only changes the frame collected (twirls, time, ending an undo merge). @@ -2081,11 +2083,7 @@ fn apply_ui_acts(app: &mut EffectcraftApp, comp: &Comp, ui_actions: Vec) } /// Runs the commands the frame collected through [`crate::menus::invoke`]. -fn apply_actions(app: &mut EffectcraftApp, ui: &mut egui::Ui, ctx: &egui::Context, actions: Vec<(String, serde_json::Value)>) { - if ui.input(|i| i.pointer.primary_down()) && actions.iter().any(|(id, _)| id == "prop.set") { - app.ui.viewer.property_interacting = true; - ctx.request_repaint(); - } +fn apply_actions(app: &mut EffectcraftApp, ctx: &egui::Context, actions: Vec<(String, serde_json::Value)>) { for (id, params) in actions { if id == "__endMerge" { app.session.history.merge_key = None; diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index ee415e36c..d71114b4d 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -265,7 +265,9 @@ pub struct ViewerState { /// The pointer is dragging in the viewer this frame (Adaptive Resolution). #[serde(skip)] pub interacting: bool, - /// A property scrub (Effect Controls, Timeline) or a Timeline drag of the playhead, keys or layer bars is in progress (Adaptive Resolution); cleared once the primary button is up. + /// A drag outside the viewer changed the frame on screen: a property scrub in Effect Controls, + /// or any Timeline or Properties drag ([`crate::panels::drag_preview`]). Adaptive Resolution + /// draws a draft until the primary button is up, which clears it. #[serde(skip)] pub property_interacting: bool, /// Extended Viewer: the comp-space region the viewer renders this frame (comp frame plus From 418a55bc4f39e21db863de2e878f69d3ec9969b2 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:00:15 +0530 Subject: [PATCH 05/12] #2042: test that thumbnail jobs can't refill a closed project's caches A Project panel thumbnail job made while a project is open, run after Close / New Project (held), or decoding through Close (gated), must leave nothing of the closed project's footage in the footage source or the layer cache. Both fail on the current code: the job decodes the old still again and keeps it. --- crates/engine/src/tests/project_release.rs | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/crates/engine/src/tests/project_release.rs b/crates/engine/src/tests/project_release.rs index 490bb6576..c8ba5f9ea 100644 --- a/crates/engine/src/tests/project_release.rs +++ b/crates/engine/src/tests/project_release.rs @@ -61,3 +61,83 @@ fn replacing_project_releases_old_footage() { assert!(recorded().contains(&"/old.mp4".to_string()), "{:?}", recorded()); assert!(s.drain_events().contains(&Event::PurgeCaches)); } + +/// A footage source with a memory cache, like the media pool: a frame read keeps its file's +/// entry until the file is forgotten. With a gate, the first read waits for the test. +#[derive(Default)] +struct Caching { + cached: Mutex>, + gate: Mutex, std::sync::mpsc::Receiver<()>)>>, +} + +impl FootageSource for Caching { + fn frame(&self, _: ItemId, footage: &Footage, _: Tick) -> Option> { + let gate = self.gate.lock().unwrap().take(); + if let Some((entered, go)) = gate { + entered.send(()).unwrap(); + go.recv().unwrap(); + } + self.cached.lock().unwrap().insert(footage.path.clone()); + Some(Arc::new(Image::new(footage.width, footage.height))) + } + fn forget(&self, path: &str) { + self.cached.lock().unwrap().remove(path); + } +} + +/// A session showing `/old.png` (a footage item, and a comp with a layer of it) through a +/// [`Caching`] source: (session, source, footage item, comp). +fn old_project() -> (Session, Arc, ItemId, ItemId) { + let mut s = Session::default(); + let src = Arc::new(Caching::default()); + s.footage = src.clone(); + let still = Footage { path: "/old.png".into(), has_video: true, width: 8, height: 8, ..Default::default() }; + let mut p = Project::default(); + let item = p.add_item("old", Default::default(), None, ItemKind::Footage(still)); + s.replace_project(p, None); + s.execute("comp.new", json!({"name": "Main", "width": 8, "height": 8, "frameRate": 30, "duration": 1})).unwrap(); + s.execute("layer.addItem", json!({"item": item.0})).unwrap(); + let comp = s.active_comp_id().unwrap(); + (s, src, item, comp) +} + +#[test] +fn held_thumbnail_jobs_cannot_refill_the_closed_projects_caches() { + for close in ["file.closeProject", "file.newProject"] { + let (mut s, src, item, comp) = old_project(); + // Project panel thumbnails, made while the project is open and run after it closed (a + // thread that started late). + let jobs = [s.thumbnail_job(item, Tick(0), 16).unwrap(), s.thumbnail_job(comp, Tick(0), 16).unwrap()]; + s.execute(close, json!({})).unwrap(); + let shown: Vec<_> = jobs.into_iter().map(|job| job()).collect(); + assert!(src.cached.lock().unwrap().is_empty(), "{close}: the closed project's frames came back"); + assert_eq!(s.layer_cache.stats().entries, 0, "{close}: the closed project's layers came back"); + assert!(shown.iter().all(Option::is_none), "{close}: a closed project's thumbnail isn't shown"); + } +} + +#[test] +fn a_thumbnail_reading_through_close_lets_go_of_what_it_read() { + let (mut s, src, item, _) = old_project(); + let (entered, entered_rx) = std::sync::mpsc::channel(); + let (go, go_rx) = std::sync::mpsc::channel(); + *src.gate.lock().unwrap() = Some((entered, go_rx)); + let job = s.thumbnail_job(item, Tick(0), 16).unwrap(); + let running = std::thread::spawn(job); + // The job is decoding the closed project's still when the project closes. + entered_rx.recv().unwrap(); + s.execute("file.closeProject", json!({})).unwrap(); + go.send(()).unwrap(); + let shown = running.join().unwrap(); + assert!(src.cached.lock().unwrap().is_empty(), "the frame decoded through Close was kept"); + assert!(shown.is_none(), "a closed project's thumbnail isn't shown"); +} + +#[test] +fn an_open_projects_thumbnails_still_render() { + let (s, src, item, comp) = old_project(); + let (w, h, px) = s.thumbnail_job(item, Tick(0), 16).unwrap()().unwrap(); + assert_eq!((w, h, px.len()), (8, 8, 8 * 8 * 4)); + assert!(s.thumbnail_job(comp, Tick(0), 16).unwrap()().is_some()); + assert!(src.cached.lock().unwrap().contains("/old.png")); +} From 365c472828cff8971d647302c41a7ea3311d9c27 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:02:57 +0530 Subject: [PATCH 06/12] #2042: closing a project calls off its thumbnail jobs Session::replace_project sets the closed project's flag (Session::project_closed) before it forgets the project's footage, and gives the next project a fresh one. A Project panel thumbnail job reads through it (CancellableFootage, #329): started after Close it reads nothing, a movie decode in flight stops early, and a job that read through Close forgets its files (and a comp thumbnail clears the layer cache) before answering None, so it can't refill the shared caches with the closed project's frames. replace_project also forgets the decoded proxies of the closed and new items, and drops the Cryptomatte probe for projects without footage. The thumbnail's pixel copy uses get(). --- crates/engine/src/lib.rs | 8 ++++ crates/engine/src/session/edit.rs | 16 ++++--- crates/engine/src/session/render.rs | 56 ++++++++++++++++++---- crates/engine/src/tests/project_release.rs | 15 ++++++ 4 files changed, 80 insertions(+), 15 deletions(-) diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 0b7608756..380358529 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -167,6 +167,13 @@ pub struct Session { pub journal: Vec<(String, Value)>, /// Processed-layer pixels reused across frames and edits (content-keyed, never stale). pub layer_cache: Arc, + /// Set when this project closes ([`Session::replace_project`]), then replaced by a fresh flag + /// for the next one: work started for the project off the UI thread (Project panel + /// thumbnails) stops reading its footage and lets go of what it read, so it can't fill the + /// shared caches with a closed project's frames. Public only so that other crates can build a + /// `Session { .. }`. + #[doc(hidden)] + pub project_closed: Arc, /// The last Cryptomatte pick probe (see [`Session::crypto_probe_job`]). Public only so that /// other crates can build a `Session { .. }`; its type is crate-private. #[doc(hidden)] @@ -351,6 +358,7 @@ impl Default for Session { events: vec![], journal: vec![], layer_cache: Arc::new(LayerCache::default()), + project_closed: Default::default(), crypto_probe: Default::default(), disk_cache: None, pending_disk_drops: Default::default(), diff --git a/crates/engine/src/session/edit.rs b/crates/engine/src/session/edit.rs index 9235dc41c..a1d994f45 100644 --- a/crates/engine/src/session/edit.rs +++ b/crates/engine/src/session/edit.rs @@ -196,6 +196,9 @@ impl Session { /// Replace the whole project (open/new), resetting history and state. pub fn replace_project(&mut self, mut p: Project, path: Option) { + // Work still running for the closed project stops reading it (see `project_closed`). + self.project_closed.store(true, std::sync::atomic::Ordering::SeqCst); + self.project_closed = Arc::default(); if self.stop_render() && let Some(mut job) = self.render_job.take() { @@ -221,14 +224,13 @@ impl Session { self.script_ui.project_epoch = self.script_ui.project_epoch.wrapping_add(1); p.fix_next_id(); upgrade_effects(&mut p); - // Let go of what the closed project decoded (frames, decoders, models), and of what the - // new project's files decoded under an earlier project: the media layer keys them by - // path, and the files may have changed since (#1070). - for it in self.project.items.values().chain(p.items.values()) { - if let effectcraft_project::ItemKind::Footage(f) = &it.kind { - self.forget_decoded(f); - } + // Let go of what the closed project's footage and proxies decoded (frames, decoders, + // models), and of what the new project's files decoded under an earlier project: the + // media layer keys them by path, and the files may have changed since (#1070). + for f in super::render::project_footage(&self.project).chain(super::render::project_footage(&p)) { + self.forget_decoded(f); } + self.drop_crypto_probe(); self.layer_cache.clear(); self.project = Arc::new(p); // The set of footage effects read the channels of is sent again, even when it is empty. diff --git a/crates/engine/src/session/render.rs b/crates/engine/src/session/render.rs index c3740196c..7e95a7bfe 100644 --- a/crates/engine/src/session/render.rs +++ b/crates/engine/src/session/render.rs @@ -1,3 +1,7 @@ +use std::sync::atomic::Ordering; + +use effectcraft_render::{CancellableFootage, FootageSource}; + use super::{EngineError, Image, ItemId, RenderOpts, Renderer, Result, Session, ThumbnailJob, Tick, Value, commands}; impl Session { @@ -77,9 +81,12 @@ impl Session { /// A Project panel thumbnail of an item (a comp at `t`, footage at its first frame), longest /// side at most `max_side`, as a job that owns everything it reads: frontends run it off the /// UI thread (a big comp takes far longer than a frame). `None` for items without pixels. + /// Once the project closes ([`Session::replace_project`]) the job reads no more and answers + /// `None`, after letting go of what it read meanwhile: a thread that started late or decoded + /// through Close can't fill the shared caches with the closed project's frames. pub fn thumbnail_job(&self, item: ItemId, t: Tick, max_side: u32) -> Option { let it = self.project.item(item)?; - let footage = self.footage.clone(); + let (footage, closed) = (self.footage.clone(), self.project_closed.clone()); match &it.kind { effectcraft_project::ItemKind::Comp(c) => { let (project, expr, cache) = (self.project.clone(), self.expr.clone(), self.layer_cache.clone()); @@ -93,21 +100,38 @@ impl Session { }; let bg = c.background; Some(Box::new(move || { - let mut r = Renderer::new(&project, footage.as_ref(), opts); + if closed.load(Ordering::SeqCst) { + return None; + } + let src = CancellableFootage { inner: footage.as_ref(), cancel: closed.clone() }; + let mut r = Renderer::new(&project, &src, opts); r.expr = expr.as_deref(); r.cache = Some(&cache); let img = r.comp_frame(item, t); + if closed.load(Ordering::SeqCst) { + project_footage(&project).for_each(|f| forget_files(footage.as_ref(), f)); + cache.clear(); + return None; + } Some((img.width, img.height, img.to_rgba8_over(bg))) })) } effectcraft_project::ItemKind::Footage(f) if f.has_video => { let f = f.clone(); Some(Box::new(move || { + if closed.load(Ordering::SeqCst) { + return None; + } // Vector footage is drawn at the thumbnail's size: its declared size can be a // 16384² canvas, gigabytes of pixels to point-sample down to a few dozen. let scale = (max_side.max(1) as f64 / f.width.max(f.height).max(1) as f64).min(1.0); - let src = footage.vector_frame(item, &f, scale).or_else(|| footage.frame(item, &f, Tick(0)))?; - let img = effectcraft_render::cineon_frame(src, &f); + let read = CancellableFootage { inner: footage.as_ref(), cancel: closed.clone() }; + let src = read.vector_frame(item, &f, scale).or_else(|| read.frame(item, &f, Tick(0))); + if closed.load(Ordering::SeqCst) { + forget_files(footage.as_ref(), &f); + return None; + } + let img = effectcraft_render::cineon_frame(src?, &f); // Point-sample down to at most `max_side` on the long side (a drawn size one // pixel over it, from rounding, is shrunk by that pixel, not halved). let (long, max) = (u64::from(img.width.max(img.height)), u64::from(max_side.max(1))); @@ -119,7 +143,7 @@ impl Session { for x in 0..w { let (sx, sy) = (u64::from(x) * u64::from(img.width) / u64::from(w), u64::from(y) * u64::from(img.height) / u64::from(h)); let i = ((sy * u64::from(img.width) + sx) * 4) as usize; - px.extend_from_slice(&full[i..i + 4]); + px.extend_from_slice(full.get(i..i + 4)?); } } Some((w, h, px)) @@ -145,9 +169,7 @@ impl Session { /// Make the media layer and the layer cache let go of what they decoded from `footage`'s /// files (it keys frames by path, so an overwritten file would keep showing its old pixels). pub(crate) fn forget_decoded(&self, footage: &effectcraft_project::Footage) { - for p in std::iter::once(&footage.path).chain(&footage.sequence) { - self.footage.forget(p); - } + forget_files(self.footage.as_ref(), footage); self.layer_cache.clear(); self.drop_crypto_probe(); } @@ -191,3 +213,21 @@ pub(crate) fn aux_footage(project: &effectcraft_project::Project) -> Vec paths.dedup(); paths } + +/// Make `src` let go of what it decoded from `footage`'s files (its file, or a sequence's). +fn forget_files(src: &dyn FootageSource, footage: &effectcraft_project::Footage) { + for p in std::iter::once(&footage.path).chain(&footage.sequence) { + src.forget(p); + } +} + +/// Every footage `project` shows: its footage items and the proxies of its items. +pub(crate) fn project_footage(project: &effectcraft_project::Project) -> impl Iterator { + project.items.values().flat_map(|it| { + let own = match &it.kind { + effectcraft_project::ItemKind::Footage(f) => Some(f), + _ => None, + }; + own.into_iter().chain(it.proxy.as_deref().map(|px| &px.footage)) + }) +} diff --git a/crates/engine/src/tests/project_release.rs b/crates/engine/src/tests/project_release.rs index c8ba5f9ea..f556b34be 100644 --- a/crates/engine/src/tests/project_release.rs +++ b/crates/engine/src/tests/project_release.rs @@ -62,6 +62,21 @@ fn replacing_project_releases_old_footage() { assert!(s.drain_events().contains(&Event::PurgeCaches)); } +#[test] +fn closing_a_project_releases_its_proxies() { + let mut s = Session::default(); + let src = Arc::new(Recording::default()); + s.footage = src.clone(); + let mut p = with_footage(&Project::default(), "old", "/old.mp4"); + let item = p.items.values_mut().next().unwrap(); + let footage = Footage { path: "/old-proxy.mov".into(), ..Default::default() }; + item.proxy = Some(Box::new(effectcraft_project::Proxy { footage, enabled: true })); + s.replace_project(p, None); + src.0.lock().unwrap().clear(); + s.execute("file.closeProject", json!({})).unwrap(); + assert!(src.0.lock().unwrap().contains(&"/old-proxy.mov".to_string()), "{:?}", src.0.lock().unwrap()); +} + /// A footage source with a memory cache, like the media pool: a frame read keeps its file's /// entry until the file is forgotten. With a gate, the first read waits for the test. #[derive(Default)] From 2da516ed84e8f1eb2bda3a9ffa3ce093ec9344c3 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:05:59 +0530 Subject: [PATCH 07/12] #2042: a decode in flight when its file is forgotten keeps nothing The media pool counts forgets and frame clears. A read-ahead (sequential playback's next frame, on its own thread) carries the count it was queued at and decodes nothing once a forget came after it; any decode keeps its frame only if no forget came while it ran. A viewer playing a movie at Close, or any reader decoding through it, can no longer bring the closed project's frames back after Session::replace_project forgot them. --- crates/media/src/pool.rs | 58 +++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/crates/media/src/pool.rs b/crates/media/src/pool.rs index 872e4fdfa..6e2e8faa4 100644 --- a/crates/media/src/pool.rs +++ b/crates/media/src/pool.rs @@ -208,6 +208,10 @@ struct CacheState { last: HashMap, i64>, /// Movies whose frames can't be kept as 8-bit levels (more bits, or shown turned). wide: HashSet>, + /// Counts [`MediaPool::forget`]s and frame clears: a decode keeps its frame only when none + /// came while it ran, so one in flight when a file is forgotten (a closed project's, or one + /// changed on disk) can't bring the frame back. + forgets: u64, } /// A movie/audio source by path ([`Opened`]), opened by the first caller while the others wait @@ -406,6 +410,7 @@ impl MediaPool { let mut c = lock(&self.inner.cache); c.lru = Lru::default(); c.last.clear(); + c.forgets = c.forgets.wrapping_add(1); drop(c); // Decoded GIFs sit outside the frame budget; Purge frees them too. lock(&self.inner.gifs).clear(); @@ -431,6 +436,7 @@ impl MediaPool { } c.last.remove(path); c.wide.remove(path); + c.forgets = c.forgets.wrapping_add(1); drop(c); crate::exr_channels::forget(path); } @@ -455,7 +461,7 @@ impl MediaPool { if lock(&self.inner.cache).wide.contains(footage.path.as_str()) { return None; } - match Inner::frame_px(&self.inner, footage, t, true, None, float, true) { + match Inner::frame_px(&self.inner, footage, t, true, None, float, true, None) { Ok(Pixels::Q8(f)) => Some(f), _ => None, } @@ -850,7 +856,7 @@ impl Inner { /// The frame of `footage` at `t`, resampled to `size` (see [`FootageSource::frame_at_size`]): /// a movie's made at that size directly, a still's resampled once and kept at that size. fn frame_at(self: &Arc, footage: &Footage, t: Tick, playback: bool, size: Option<(u32, u32)>, float: FloatCurve) -> Result> { - match Self::frame_px(self, footage, t, playback, size, float, false)? { + match Self::frame_px(self, footage, t, playback, size, float, false, None)? { Pixels::F32(img) => Ok(img), // (a float request's key never holds 8-bit levels) Pixels::Q8(_) => Err(MediaError::Decode(format!("{}: 8-bit frame for a float request", footage.path))), @@ -859,8 +865,20 @@ impl Inner { /// [`Self::frame_at`], kept as 8-bit levels when `q8` is set and the frame has 8 bits (a /// float frame under the float key otherwise, and the movie is remembered as `wide`). + /// `since`: the [`CacheState::forgets`] count the read was asked at (a read-ahead's, when it + /// was queued); a read that missed is not decoded once a forget came after it, and a frame + /// decoded while one came is not kept. #[allow(clippy::too_many_arguments)] - fn frame_px(self: &Arc, footage: &Footage, t: Tick, playback: bool, size: Option<(u32, u32)>, float: FloatCurve, q8: bool) -> Result { + fn frame_px( + self: &Arc, + footage: &Footage, + t: Tick, + playback: bool, + size: Option<(u32, u32)>, + float: FloatCurve, + q8: bool, + since: Option, + ) -> Result { if !footage.has_video { return Err(MediaError::Unsupported(format!("{}: no video", footage.path))); } @@ -909,6 +927,10 @@ impl Inner { } c = self.done.wait(c).unwrap_or_else(std::sync::PoisonError::into_inner); } + let since = since.unwrap_or(c.forgets); + if c.forgets != since { + return Err(MediaError::Cancelled); + } self.misses.fetch_add(1, Ordering::Relaxed); c.inflight.insert(loc.key.clone()); drop(c); @@ -917,6 +939,9 @@ impl Inner { reads::note_all(&files); let img = img?; let mut c = lock(&self.cache); + if c.forgets != since { + return Ok(img); + } if q8 && let Pixels::F32(_) = img { // not 8-bit: kept as the float frame it is, which the renderer asks for next c.wide.insert(loc.key.path.clone()); @@ -935,23 +960,23 @@ impl Inner { next.key.size = loc.key.size; next.key.q8 = loc.key.q8; if next.key != loc.key && !c.lru.map.contains_key(&next.key) && !c.inflight.contains(&next.key) { - self.prefetch(footage, next_t, size, float, loc.key.q8); + self.prefetch(footage, next_t, size, float, loc.key.q8, c.forgets); } } } #[cfg(not(target_arch = "wasm32"))] - fn prefetch(self: &Arc, footage: &Footage, t: Tick, size: Option<(u32, u32)>, float: FloatCurve, q8: bool) { + fn prefetch(self: &Arc, footage: &Footage, t: Tick, size: Option<(u32, u32)>, float: FloatCurve, q8: bool, since: u64) { let (me, f) = (self.clone(), footage.clone()); self.prefetched.fetch_add(1, Ordering::Relaxed); // A plain thread, not a rayon job: the decode below parallelises with rayon itself. std::thread::spawn(move || { - let _ = me.frame_px(&f, t, false, size, float, q8); + let _ = me.frame_px(&f, t, false, size, float, q8, Some(since)); }); } #[cfg(target_arch = "wasm32")] - fn prefetch(self: &Arc, _footage: &Footage, _t: Tick, _size: Option<(u32, u32)>, _float: FloatCurve, _q8: bool) {} + fn prefetch(self: &Arc, _footage: &Footage, _t: Tick, _size: Option<(u32, u32)>, _float: FloatCurve, _q8: bool, _since: u64) {} /// A still (image file or sequence frame) at `loc.key.size` when one is set: resampled as the /// renderer would ([`FootageSource::frame_at_size`]), so the pool keeps the reduced frame and a @@ -1203,6 +1228,25 @@ fn lock(m: &Mutex) -> std::sync::MutexGuard<'_, T> { mod tests { use super::*; + /// #2042: a read queued before its file was forgotten (a read-ahead of a closed project's + /// movie, started from the frame before) decodes nothing and keeps nothing; a read asked + /// after the forget decodes and keeps its frame. + #[test] + fn reads_queued_before_a_forget_keep_nothing() { + let mut png = std::io::Cursor::new(Vec::new()); + image::RgbaImage::new(2, 2).write_to(&mut png, image::ImageFormat::Png).unwrap(); + let pool = MediaPool::new(); + pool.add_bytes("/a.png", png.into_inner().into()); + let f = Footage { path: "/a.png".into(), kind: FootageKind::Still, width: 2, height: 2, has_video: true, ..Default::default() }; + let queued = lock(&pool.inner.cache).forgets; + pool.forget("/a.png"); + let read = Inner::frame_px(&pool.inner, &f, Tick::ZERO, false, None, FloatCurve::Srgb, false, Some(queued)); + assert!(matches!(read, Err(MediaError::Cancelled)), "{:?}", read.err()); + assert_eq!(pool.stats().frames, 0, "the forgotten file's frame came back"); + pool.frame_at(&f, Tick::ZERO).unwrap(); + assert_eq!(pool.stats().frames, 1); + } + /// Conforming a long file's audio reads every chunk at its own time: the sample index times /// ticks per second overflowed `i64` past 12:36 at 48 kHz, and later chunks came out silent /// (#172). From 9ed7954a9742104e8d3a6ff6bffbb23562845637 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:08:18 +0530 Subject: [PATCH 08/12] #2047: markers no expression reads don't drop the resolution Compare the comp the way the frame cache does (#1083): markers count as pixels only when an expression reads them, so dragging a marker keeps Full. Tighten the click and Fast Previews Off tests so they prove the gesture reached the app. --- crates/ui-egui/src/panels/drag_preview.rs | 17 +++++++++-------- .../tests/it/ui_timeline_interacting.rs | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/panels/drag_preview.rs b/crates/ui-egui/src/panels/drag_preview.rs index 9d0d42f7b..4384095c7 100644 --- a/crates/ui-egui/src/panels/drag_preview.rs +++ b/crates/ui-egui/src/panels/drag_preview.rs @@ -8,9 +8,9 @@ use effectcraft_engine::project::{Comp, ItemId}; use crate::EffectcraftApp; -/// The frame on screen when a panel starts its pass: the active comp and its current frame. -/// [`DragWatch::end`] compares it with the frame after the panel ran its gestures, so every drag -/// the panel handles is covered without a flag per gesture. +/// The active comp and its current frame index when a panel starts its pass. [`DragWatch::end`] +/// compares them with the comp and frame after the panel ran its gestures, so every drag the +/// panel handles is covered without a flag per gesture. pub(crate) struct DragWatch { before: Option<(ItemId, Arc, i64)>, } @@ -25,10 +25,11 @@ impl DragWatch { Self { before } } - /// While the primary button drags (moved past a click), a change of the current frame or of - /// the active comp's pixels since [`Self::begin`] sets `property_interacting`, which stays - /// set until the button is up (`App::frame`). A click, a held button, or a drag that draws - /// the same pixels (scrolling, zooming, the work area, selecting) keeps Full. + /// While the primary button drags (moved past a click, or held past one), a change of the + /// current frame or of the active comp's pixels since [`Self::begin`] sets + /// `property_interacting`, which stays set until the button is up (`App::frame`). A click, + /// or a drag that draws the same pixels (scrolling, zooming, the work area, selecting, markers + /// no expression reads, as for the frame cache) keeps Full. pub(crate) fn end(self, app: &mut EffectcraftApp, ctx: &egui::Context) { let Some((id, comp, frame)) = self.before else { return }; if app.ui.viewer.property_interacting || !ctx.input(|i| i.pointer.primary_down() && i.pointer.is_decidedly_dragging()) { @@ -39,7 +40,7 @@ impl DragWatch { } let Some(now) = app.session.project.comp_arc(id) else { return }; let moved = comp.frame_rate.frame_at(app.session.time()) != frame; - if moved || (!Arc::ptr_eq(&comp, &now) && !now.same_pixels(&comp)) { + if moved || (!Arc::ptr_eq(&comp, &now) && !now.same_pixels_with(&comp, app.session.project.reads_markers(), &|_| false)) { app.ui.viewer.property_interacting = true; ctx.request_repaint(); } diff --git a/crates/ui-egui/tests/it/ui_timeline_interacting.rs b/crates/ui-egui/tests/it/ui_timeline_interacting.rs index 6ed4c719a..e2cb2112a 100644 --- a/crates/ui-egui/tests/it/ui_timeline_interacting.rs +++ b/crates/ui-egui/tests/it/ui_timeline_interacting.rs @@ -158,24 +158,42 @@ fn work_area_drag_keeps_full_resolution() { release(&mut f.h, from); } +/// Markers are pixels only to the expressions that read them (#1083): moving one keeps Full. +#[test] +fn marker_drag_keeps_full_resolution() { + let mut f = fixture("adaptive"); + f.h.state_mut().session.execute("comp.addMarker", json!({"time": 2.0})).unwrap(); + f.h.run_steps(3); + let from = rect(&f.h, "timeline.marker.0").center(); + let before = f.h.state().session.active_comp().unwrap().markers[0].time; + hold(&mut f.h, from, from + vec2(80.0, 0.0)); + assert_ne!(f.h.state().session.active_comp().unwrap().markers[0].time, before, "the marker moved"); + assert!(!draft(&f.h), "a marker no expression reads changes no pixels"); + release(&mut f.h, from); +} + #[test] fn timeline_click_keeps_full_resolution() { let mut f = fixture("adaptive"); let point = rect(&f.h, "timeline.ruler").center(); + let before = f.h.state().session.time(); f.h.input_mut().events.push(Event::PointerMoved(point)); f.h.step(); f.h.input_mut().events.push(Event::PointerButton { pos: point, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); f.h.run_steps(3); + assert_ne!(f.h.state().session.time(), before, "the click moved the playhead"); assert!(!draft(&f.h)); release(&mut f.h, point); } +/// The drag is still noted, but Fast Previews Off never lowers the resolution. #[test] fn fast_previews_off_keeps_full_resolution() { let mut f = fixture("off"); let ruler = rect(&f.h, "timeline.ruler"); let from = pos2(ruler.min.x + 40.0, ruler.max.y - 3.0); hold(&mut f.h, from, from + vec2(200.0, 0.0)); + assert!(f.h.state().ui.viewer.property_interacting); assert!(!draft(&f.h)); release(&mut f.h, from); } From 66337085711dcc32d1279188fddda77fac9e53b6 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:12:26 +0530 Subject: [PATCH 09/12] #2042: a cache purge drops the Project panel's thumbnails Event::PurgeCaches (Close / New / Open Project, Edit > Purge, footage reloads) now also removes the Project panel's thumbnail textures and the renders awaited for them. They were keyed by item id only: the closed project's textures stayed in memory, and an item of the next project with a closed one's id showed the closed project's picture until its own render landed. --- crates/ui-egui/src/app/frame.rs | 1 + crates/ui-egui/src/panels/project.rs | 47 +++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/app/frame.rs b/crates/ui-egui/src/app/frame.rs index b78c38c73..63101350d 100644 --- a/crates/ui-egui/src/app/frame.rs +++ b/crates/ui-egui/src/app/frame.rs @@ -153,6 +153,7 @@ impl EffectcraftApp { } effectcraft_engine::Event::PurgeCaches => { self.frames.clear(); + crate::panels::project::forget_thumbnails(ctx); // (frames made after it get keys of their own: see `Self::purge_stamp`) self.purges = self.purges.wrapping_add(1); } diff --git a/crates/ui-egui/src/panels/project.rs b/crates/ui-egui/src/panels/project.rs index 8d67fd9ee..bc03d282f 100644 --- a/crates/ui-egui/src/panels/project.rs +++ b/crates/ui-egui/src/panels/project.rs @@ -119,8 +119,22 @@ pub fn drop_folder(project: &effectcraft_engine::project::Project, row: Option)>>>>); +#[derive(Clone)] +struct PendingThumb(u64, Arc)>>>>); + +/// Let go of every Project panel thumbnail and the renders in flight for them (a cache purge, or +/// a project closed: the next project's item ids can be the closed one's). +pub fn forget_thumbnails(ctx: &egui::Context) { + ctx.data_mut(|d| { + d.remove_by_type::(); + d.remove_by_type::(); + }); +} /// Thumbnail of a comp (its current time) or footage (first frame), cached per item/revision. /// Rendered on a background thread (inline on wasm32): until the new one lands the previous @@ -129,19 +143,19 @@ fn thumbnail(app: &EffectcraftApp, ctx: &egui::Context, it: &Item) -> Option = ctx.data(|d| d.get_temp(key)); - let mut tex = cached.as_ref().map(|(_, t)| t.clone()); - let have = cached.as_ref().map(|(r, _)| *r); + let cached: Option = ctx.data(|d| d.get_temp(key)); + let mut tex = cached.as_ref().map(|Thumb(_, t)| t.clone()); + let have = cached.as_ref().map(|Thumb(r, _)| *r); // A finished render: upload it. let pending: Option = ctx.data(|d| d.get_temp(pkey)); - if let Some((prev, slot)) = &pending { + if let Some(PendingThumb(prev, slot)) = &pending { let done = slot.lock().ok().and_then(|mut s| s.take()); match done { Some(Some((w, h, px))) => { let ci = egui::ColorImage::from_rgba_unmultiplied([w as usize, h as usize], &px); let t = ctx.load_texture(format!("proj-thumb-{}", it.id.0), ci, egui::TextureOptions::LINEAR); ctx.data_mut(|d| { - d.insert_temp(key, (*prev, t.clone())); + d.insert_temp(key, Thumb(*prev, t.clone())); d.remove::(pkey); }); tex = Some(t); @@ -179,7 +193,7 @@ fn thumbnail(app: &EffectcraftApp, ctx: &egui::Context, it: &Item) -> Option(pkey, (rev, slot))); + ctx.data_mut(|d| d.insert_temp(pkey, PendingThumb(rev, slot))); ctx.request_repaint(); tex } @@ -1504,6 +1518,25 @@ mod tests { } } + /// #2042: closing the project drops the Project panel's thumbnails (and renders in flight), + /// so their textures go with it and an item of the next project with a closed one's id never + /// shows the closed project's picture. + #[test] + fn closing_the_project_forgets_its_thumbnails() { + let mut app = EffectcraftApp::new(effectcraft_engine::Session::default()); + let ctx = egui::Context::default(); + let (key, pkey) = (egui::Id::unique(("proj-thumb", 1u64)), egui::Id::unique(("proj-thumb-pending", 1u64))); + let tex = ctx.load_texture("t", egui::ColorImage::from_rgba_unmultiplied([1, 1], &[255; 4]), egui::TextureOptions::LINEAR); + ctx.data_mut(|d| { + d.insert_temp(key, Thumb(app.session.revision, tex)); + d.insert_temp(pkey, PendingThumb(app.session.revision, Arc::default())); + }); + app.session.execute("file.closeProject", serde_json::json!({})).unwrap(); + app.handle_events(&ctx); + assert!(ctx.data(|d| d.get_temp::(key)).is_none(), "the closed project's thumbnail is kept"); + assert!(ctx.data(|d| d.get_temp::(pkey)).is_none(), "a closed project's render is awaited"); + } + /// Long names show in full: the Name column fits them (it stopped at 260 points with "…") /// up to the panel's width less the Label column and, while optional columns show, room for /// them; a width the user dragged wins. From 8b481f3811ab3d276c78d331ef80d6a76dc2f676 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:18:24 +0530 Subject: [PATCH 10/12] #2047: a layer's audio counts when something draws it Compare the comp exactly as the frame cache does: a layer's Audio switch, Audio group and audio effects are pixels when a layer picks its audio or an expression reads audio, before or after the edit. Scrubbing Audio Levels read by an expression now draws a draft; with nothing drawing the audio it keeps Full. --- crates/ui-egui/src/panels/drag_preview.rs | 36 +++++++++++-------- .../tests/it/ui_timeline_interacting.rs | 30 ++++++++++++++++ 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/crates/ui-egui/src/panels/drag_preview.rs b/crates/ui-egui/src/panels/drag_preview.rs index 4384095c7..e0f53fb12 100644 --- a/crates/ui-egui/src/panels/drag_preview.rs +++ b/crates/ui-egui/src/panels/drag_preview.rs @@ -4,43 +4,49 @@ use std::sync::Arc; -use effectcraft_engine::project::{Comp, ItemId}; +use effectcraft_engine::project::{ItemId, Project}; use crate::EffectcraftApp; -/// The active comp and its current frame index when a panel starts its pass. [`DragWatch::end`] -/// compares them with the comp and frame after the panel ran its gestures, so every drag the -/// panel handles is covered without a flag per gesture. +/// The project, the active comp and its current frame index when a panel starts its pass. +/// [`DragWatch::end`] compares them with the comp and frame after the panel ran its gestures, so +/// every drag the panel handles is covered without a flag per gesture. pub(crate) struct DragWatch { - before: Option<(ItemId, Arc, i64)>, + before: Option<(ItemId, Arc, i64)>, } impl DragWatch { pub(crate) fn begin(app: &EffectcraftApp) -> Self { + let project = app.session.project.clone(); let before = app.session.active_comp_id().and_then(|id| { - let comp = app.session.project.comp_arc(id)?; - let frame = comp.frame_rate.frame_at(app.session.time()); - Some((id, comp, frame)) + let frame = project.comp_arc(id)?.frame_rate.frame_at(app.session.time()); + Some((id, project, frame)) }); Self { before } } /// While the primary button drags (moved past a click, or held past one), a change of the /// current frame or of the active comp's pixels since [`Self::begin`] sets - /// `property_interacting`, which stays set until the button is up (`App::frame`). A click, - /// or a drag that draws the same pixels (scrolling, zooming, the work area, selecting, markers - /// no expression reads, as for the frame cache) keeps Full. + /// `property_interacting`, which stays set until the button is up (`App::frame`). Pixels are + /// compared as the frame cache does: markers count when an expression reads them, a layer's + /// audio when something draws it, before or after the edit. A click, or a drag that draws + /// the same pixels (scrolling, zooming, the work area, selecting) keeps Full. pub(crate) fn end(self, app: &mut EffectcraftApp, ctx: &egui::Context) { - let Some((id, comp, frame)) = self.before else { return }; + let Some((id, project, frame)) = self.before else { return }; if app.ui.viewer.property_interacting || !ctx.input(|i| i.pointer.primary_down() && i.pointer.is_decidedly_dragging()) { return; } if app.session.active_comp_id() != Some(id) { return; } - let Some(now) = app.session.project.comp_arc(id) else { return }; - let moved = comp.frame_rate.frame_at(app.session.time()) != frame; - if moved || (!Arc::ptr_eq(&comp, &now) && !now.same_pixels_with(&comp, app.session.project.reads_markers(), &|_| false)) { + let (Some(was), Some(now)) = (project.comp_arc(id), app.session.project.comp_arc(id)) else { return }; + let moved = was.frame_rate.frame_at(app.session.time()) != frame; + let edited = || { + let current = &app.session.project; + let heard = current.heard_layers().union(&project.heard_layers()); + !now.same_pixels_with(&was, current.reads_markers(), &|l| heard.contains(id, l)) + }; + if moved || (!Arc::ptr_eq(&was, &now) && edited()) { app.ui.viewer.property_interacting = true; ctx.request_repaint(); } diff --git a/crates/ui-egui/tests/it/ui_timeline_interacting.rs b/crates/ui-egui/tests/it/ui_timeline_interacting.rs index e2cb2112a..5cf11ad0e 100644 --- a/crates/ui-egui/tests/it/ui_timeline_interacting.rs +++ b/crates/ui-egui/tests/it/ui_timeline_interacting.rs @@ -158,6 +158,36 @@ fn work_area_drag_keeps_full_resolution() { release(&mut f.h, from); } +/// Scrubs the precomp's Audio Levels in the Timeline; `reads_audio` adds an expression that +/// reads audio. Returns whether the viewer drew a draft while held. +fn audio_levels_scrub(reads_audio: bool) -> bool { + let mut f = fixture("adaptive"); + if reads_audio { + let rotation = json!({"layer": f.solid, "path": "transform/rotation", "expression": "thisComp.layer(1).audioLevels; value"}); + f.h.state_mut().session.execute("prop.setExpression", rotation).unwrap(); + } + let uid = f.h.state().session.active_comp().unwrap().layers.iter().find(|l| l.id.0 == f.pre).unwrap().props.prop("audio/levels").unwrap().uid; + let tl = &mut f.h.state_mut().ui.timeline; + tl.open_layers.insert(f.pre); + tl.layer_reveal.insert(f.pre, vec!["props".into()]); + tl.reveal_props.insert(uid); + f.h.run_steps(3); + let from = rect(&f.h, &format!("timeline.prop.{uid}.value.0")).center(); + let before = on_screen(&f.h); + hold(&mut f.h, from, from + vec2(40.0, 0.0)); + assert_ne!(on_screen(&f.h), before, "the scrub changed the levels"); + let draft = draft(&f.h); + release(&mut f.h, from); + draft +} + +/// A layer's audio is pixels only when something draws it (an expression reading audio here). +#[test] +fn audio_levels_scrub_draws_a_draft_only_when_audio_is_drawn() { + assert!(audio_levels_scrub(true), "an expression reads the audio"); + assert!(!audio_levels_scrub(false), "nothing draws the audio"); +} + /// Markers are pixels only to the expressions that read them (#1083): moving one keeps Full. #[test] fn marker_drag_keeps_full_resolution() { From 0635f2496d9da71332671f3dd8522266058bd5a8 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 19:32:06 +0530 Subject: [PATCH 11/12] #2042: review fixes for closing a project's thumbnails - CancellableFootage calls off vector_frame too: a closed project's SVG / PDF thumbnail stops before it rasterises, like a viewer frame nobody waits for. - replace_project forgets every footage file once and clears the layer cache and the Cryptomatte probe once, instead of once per footage item. - The through-Close test covers comp thumbnails (layer cache and footage) as well as footage ones, and fails with a timeout instead of hanging. - Docs: forget is also how a closed project's files go. --- crates/engine/src/session/edit.rs | 2 +- crates/engine/src/session/render.rs | 2 +- crates/engine/src/tests/project_release.rs | 31 ++++++++++++---------- crates/media/src/pool.rs | 10 ++++--- crates/render/src/footage.rs | 8 +++--- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/crates/engine/src/session/edit.rs b/crates/engine/src/session/edit.rs index a1d994f45..7d2a20949 100644 --- a/crates/engine/src/session/edit.rs +++ b/crates/engine/src/session/edit.rs @@ -228,7 +228,7 @@ impl Session { // models), and of what the new project's files decoded under an earlier project: the // media layer keys them by path, and the files may have changed since (#1070). for f in super::render::project_footage(&self.project).chain(super::render::project_footage(&p)) { - self.forget_decoded(f); + super::render::forget_files(self.footage.as_ref(), f); } self.drop_crypto_probe(); self.layer_cache.clear(); diff --git a/crates/engine/src/session/render.rs b/crates/engine/src/session/render.rs index 7e95a7bfe..fe1634945 100644 --- a/crates/engine/src/session/render.rs +++ b/crates/engine/src/session/render.rs @@ -215,7 +215,7 @@ pub(crate) fn aux_footage(project: &effectcraft_project::Project) -> Vec } /// Make `src` let go of what it decoded from `footage`'s files (its file, or a sequence's). -fn forget_files(src: &dyn FootageSource, footage: &effectcraft_project::Footage) { +pub(crate) fn forget_files(src: &dyn FootageSource, footage: &effectcraft_project::Footage) { for p in std::iter::once(&footage.path).chain(&footage.sequence) { src.forget(p); } diff --git a/crates/engine/src/tests/project_release.rs b/crates/engine/src/tests/project_release.rs index f556b34be..f7fb91b99 100644 --- a/crates/engine/src/tests/project_release.rs +++ b/crates/engine/src/tests/project_release.rs @@ -132,20 +132,23 @@ fn held_thumbnail_jobs_cannot_refill_the_closed_projects_caches() { } #[test] -fn a_thumbnail_reading_through_close_lets_go_of_what_it_read() { - let (mut s, src, item, _) = old_project(); - let (entered, entered_rx) = std::sync::mpsc::channel(); - let (go, go_rx) = std::sync::mpsc::channel(); - *src.gate.lock().unwrap() = Some((entered, go_rx)); - let job = s.thumbnail_job(item, Tick(0), 16).unwrap(); - let running = std::thread::spawn(job); - // The job is decoding the closed project's still when the project closes. - entered_rx.recv().unwrap(); - s.execute("file.closeProject", json!({})).unwrap(); - go.send(()).unwrap(); - let shown = running.join().unwrap(); - assert!(src.cached.lock().unwrap().is_empty(), "the frame decoded through Close was kept"); - assert!(shown.is_none(), "a closed project's thumbnail isn't shown"); +fn thumbnails_reading_through_close_let_go_of_what_they_read() { + for which in ["footage", "comp"] { + let (mut s, src, item, comp) = old_project(); + let (entered, entered_rx) = std::sync::mpsc::channel(); + let (go, go_rx) = std::sync::mpsc::channel(); + *src.gate.lock().unwrap() = Some((entered, go_rx)); + let job = s.thumbnail_job(if which == "comp" { comp } else { item }, Tick(0), 16).unwrap(); + let running = std::thread::spawn(job); + // The job is decoding the closed project's still when the project closes. + entered_rx.recv_timeout(std::time::Duration::from_secs(30)).unwrap(); + s.execute("file.closeProject", json!({})).unwrap(); + go.send(()).unwrap(); + let shown = running.join().unwrap(); + assert!(src.cached.lock().unwrap().is_empty(), "{which}: the frame decoded through Close was kept"); + assert_eq!(s.layer_cache.stats().entries, 0, "{which}: the closed project's layers were kept"); + assert!(shown.is_none(), "{which}: a closed project's thumbnail isn't shown"); + } } #[test] diff --git a/crates/media/src/pool.rs b/crates/media/src/pool.rs index 6e2e8faa4..9e87c1575 100644 --- a/crates/media/src/pool.rs +++ b/crates/media/src/pool.rs @@ -423,7 +423,9 @@ impl MediaPool { lock(&self.inner.problems).clear(); } - /// Forget a file (after it changed on disk, or to retry a file that failed to open). + /// Forget a file (after it changed on disk or its project closed, or to retry a file that + /// failed to open). A decode of any file in flight meanwhile keeps nothing (see + /// [`CacheState::forgets`]). pub fn forget(&self, path: &str) { lock(&self.inner.sources).remove(path); lock(&self.inner.models).remove(path); @@ -1228,9 +1230,9 @@ fn lock(m: &Mutex) -> std::sync::MutexGuard<'_, T> { mod tests { use super::*; - /// #2042: a read queued before its file was forgotten (a read-ahead of a closed project's - /// movie, started from the frame before) decodes nothing and keeps nothing; a read asked - /// after the forget decodes and keeps its frame. + /// #2042: a read queued before its file was forgotten (as a read-ahead of a closed project's + /// movie is, by the read of the frame before) decodes nothing and keeps nothing; a read asked + /// after the forget decodes and keeps its frame. (A still stands in for the movie.) #[test] fn reads_queued_before_a_forget_keep_nothing() { let mut png = std::io::Cursor::new(Vec::new()); diff --git a/crates/render/src/footage.rs b/crates/render/src/footage.rs index c14961d0f..9c4b2527c 100644 --- a/crates/render/src/footage.rs +++ b/crates/render/src/footage.rs @@ -73,9 +73,9 @@ pub trait FootageSource: Send + Sync { /// Drop the decoded frames it keeps (Edit ▸ Purge ▸ All Memory / Image Cache Memory): the /// next reads decode again. Sources without a cache ignore it. fn purge(&self) {} - /// The file at `path` changed on disk (Reload Footage): drop what it keeps of it (decoded - /// frames, open decoders, parsed models), so the next reads see the new contents. Sources - /// without a cache ignore it. + /// The file at `path` changed on disk (Reload Footage), or the project showing it closed: + /// drop what it keeps of it (decoded frames, open decoders, parsed models), so the next reads + /// see the new contents. Sources without a cache ignore it. fn forget(&self, _path: &str) {} /// Settings ▸ Disk ▸ Conformed Audio Folder: where decoded audio is kept between reads /// (`None` = off); sources that don't decode audio ignore it. @@ -205,7 +205,7 @@ impl FootageSource for CancellableFootage<'_> { self.inner.cache_budget() } fn vector_frame(&self, item: ItemId, footage: &Footage, scale: f64) -> Option> { - self.inner.vector_frame(item, footage, scale) + self.read(|| self.inner.vector_frame(item, footage, scale)) } fn cancellable(&self, cancel: &Arc, f: &mut dyn FnMut()) { self.inner.cancellable(cancel, f) From 9046c8d39a96102bd1c8839cb109aa0e22ff71d6 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Thu, 12 Nov 2026 20:03:35 +0530 Subject: [PATCH 12/12] #2042: read the Project panel thumbnail through panels::project::cached_thumbnail ui_large_project::comp_thumbnail_renders_off_the_ui_thread read the thumbnail cache by its old storage type, (u64, TextureHandle), which the purge change replaced with a private newtype, so it never saw the texture land. It now asks cached_thumbnail. --- crates/ui-egui/src/panels/project.rs | 5 +++++ crates/ui-egui/tests/it/ui_large_project.rs | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/panels/project.rs b/crates/ui-egui/src/panels/project.rs index bc03d282f..0d8074934 100644 --- a/crates/ui-egui/src/panels/project.rs +++ b/crates/ui-egui/src/panels/project.rs @@ -127,6 +127,11 @@ struct Thumb(u64, egui::TextureHandle); #[derive(Clone)] struct PendingThumb(u64, Arc)>>>>); +/// The Project panel's thumbnail texture of `item`, once its render has landed. +pub fn cached_thumbnail(ctx: &egui::Context, item: ItemId) -> Option { + ctx.data(|d| d.get_temp::(egui::Id::unique(("proj-thumb", item.0)))).map(|Thumb(_, t)| t) +} + /// Let go of every Project panel thumbnail and the renders in flight for them (a cache purge, or /// a project closed: the next project's item ids can be the closed one's). pub fn forget_thumbnails(ctx: &egui::Context) { diff --git a/crates/ui-egui/tests/it/ui_large_project.rs b/crates/ui-egui/tests/it/ui_large_project.rs index 4e2476269..2310087e3 100644 --- a/crates/ui-egui/tests/it/ui_large_project.rs +++ b/crates/ui-egui/tests/it/ui_large_project.rs @@ -64,9 +64,7 @@ fn comp_thumbnail_renders_off_the_ui_thread() { let mut landed = false; for _ in 0..400 { h.step(); - if h.state().auto.find("project.thumbnail").is_some() - && h.ctx.data(|d| d.get_temp::<(u64, egui::TextureHandle)>(egui::Id::unique(("proj-thumb", main.0)))).is_some() - { + if h.state().auto.find("project.thumbnail").is_some() && effectcraft_ui_egui::panels::project::cached_thumbnail(&h.ctx, main).is_some() { landed = true; break; }