Footage cache (#3271): the Project panel's thumbnail key follows footage reloads

The panel worked a thumbnail's content key out again only when the project's revision or the time changed, so a Reload Footage or a watched file that changed (the revision stays) kept the old key and the old thumbnail. The footage reload count is now part of the panel's check. A panel test bumps the reload count alone; it fails on the old code.
This commit is contained in:
vangel76 committed 2026-11-08 10:39:41 +01:00
1 parent 2130d01d4a
commit 1aa604789f
2 files changed
+40 -4

No files matched your search

+10 -4
View File
@@ -123,13 +123,15 @@ pub fn drop_folder(project: &effectcraft_engine::project::Project, row: Option<I
type PendingThumb = (u128, Arc<Mutex<Option<Option<(u32, u32, Vec<u8>)>>>>);
/// 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::<ThumbKey>(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::<ThumbKey>(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;
@@ -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());