#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.
This commit is contained in:
arnav-hiwarkar committed 2026-11-12 19:32:06 +05:30
1 parent 8bde3dc53f
commit 0635f2496d
5 files changed
+29 -24

No files matched your search

+1 -1
View File
@@ -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();
+1 -1
View File
@@ -215,7 +215,7 @@ pub(crate) fn aux_footage(project: &effectcraft_project::Project) -> Vec<String>
}
/// 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);
}
+17 -14
View File
@@ -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]
+6 -4
View File
@@ -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<T>(m: &Mutex<T>) -> 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());
+4 -4
View File
@@ -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<Arc<Image>> {
self.inner.vector_frame(item, footage, scale)
self.read(|| self.inner.vector_frame(item, footage, scale))
}
fn cancellable(&self, cancel: &Arc<AtomicBool>, f: &mut dyn FnMut()) {
self.inner.cancellable(cancel, f)