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)