diff --git a/crates/ui-egui/src/panels/project.rs b/crates/ui-egui/src/panels/project.rs index ba9da58ae..d401b021d 100644 --- a/crates/ui-egui/src/panels/project.rs +++ b/crates/ui-egui/src/panels/project.rs @@ -123,13 +123,15 @@ pub fn drop_folder(project: &effectcraft_engine::project::Project, row: Option)>>>>); /// The content key of item `it`'s thumbnail at `t` ([`effectcraft_engine::Session::thumbnail_key`]), -/// worked out again only when the project's revision or the time changed. +/// worked out again only when the project's revision, the footage reloads (Reload Footage or a +/// watched file that changed: the project's revision stays) or the time changed. fn thumbnail_key(app: &EffectcraftApp, ctx: &egui::Context, it: &Item, t: effectcraft_engine::time::Tick) -> u128 { let id = egui::Id::unique(("proj-thumb-key", it.id.0)); let rev = app.session.revision; + let reloads = app.session.footage_reloads.load(std::sync::atomic::Ordering::Relaxed); let now = ctx.input(|i| i.time); - if let Some((r, at, k, when)) = ctx.data(|d| d.get_temp::<(u64, i64, u128, f64)>(id)) { - if r == rev && at == t.0 { + if let Some((r, n, at, k, when)) = ctx.data(|d| d.get_temp::(id)) { + if r == rev && n == reloads && at == t.0 { return k; } // (the key hashes the comp's content: while edits come fast, at most every 0.25 s) @@ -140,10 +142,14 @@ fn thumbnail_key(app: &EffectcraftApp, ctx: &egui::Context, it: &Item, t: effect } // (no key: the revision stands in, as before) let k = app.session.thumbnail_key(it.id, t, THUMB_SIDE).unwrap_or(u128::from(rev) | (1 << 127)); - ctx.data_mut(|d| d.insert_temp(id, (rev, t.0, k, now))); + ctx.data_mut(|d| d.insert_temp::(id, (rev, reloads, t.0, k, now))); k } +/// A thumbnail's content key as last worked out: (project revision, footage reloads, time, key, +/// when, in seconds of UI time). +type ThumbKey = (u64, u64, i64, u128, f64); + /// The longest side of a Project panel thumbnail, in pixels. const THUMB_SIDE: u32 = 192; diff --git a/crates/ui-egui/tests/it/ui_large_project.rs b/crates/ui-egui/tests/it/ui_large_project.rs index f645623dc..dc42097ae 100644 --- a/crates/ui-egui/tests/it/ui_large_project.rs +++ b/crates/ui-egui/tests/it/ui_large_project.rs @@ -75,6 +75,36 @@ fn comp_thumbnail_renders_off_the_ui_thread() { assert!(landed, "thumbnail texture"); } +/// #3271 review: a footage reload that leaves the project's revision as it was (File ▸ Reload +/// Footage, a watched file that changed) gives the Project panel's thumbnail a new key. +#[test] +fn a_footage_reload_gives_the_panel_thumbnail_a_new_key() { + let mut h = harness(large()); + let main = h.state().session.active_comp_id().unwrap(); + h.state_mut().session.execute("project.select", json!({"items": [main.0]})).unwrap(); + h.state_mut().show_panel(PanelKind::Project); + let id = egui::Id::unique(("proj-thumb-key", main.0)); + let shown = |h: &egui_kittest::Harness<'_, EffectcraftApp>| h.ctx.data(|d| d.get_temp::<(u64, u64, i64, u128, f64)>(id)).map(|k| k.3); + let want = |h: &egui_kittest::Harness<'_, EffectcraftApp>| h.state().session.thumbnail_key(main, effectcraft_engine::time::Tick::ZERO, 192); + h.run_steps(2); + let before = shown(&h); + assert!(before.is_some() && before == want(&h)); + let rev = h.state().session.revision; + h.state().session.footage_reloads.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + assert_eq!(h.state().session.revision, rev); + let mut now = before; + for _ in 0..100 { + h.step(); + now = shown(&h); + if now != before { + break; + } + std::thread::sleep(std::time::Duration::from_millis(10)); + } + assert_ne!(now, before, "a new key after the reload"); + assert_eq!(now, want(&h)); +} + #[test] fn timeline_reaches_the_last_of_many_layers() { let mut h = harness(large());