diff --git a/crates/media/src/exr_planes.rs b/crates/media/src/exr_planes.rs index 682c94c80..7a0d8a4c7 100644 --- a/crates/media/src/exr_planes.rs +++ b/crates/media/src/exr_planes.rs @@ -261,9 +261,10 @@ struct Entry { path: String, batch: Option>, flight: Option>, - /// Requests that failed for good (unreadable, too large) and why: a request asking for at + /// Requests that failed for good (unreadable, too large), the index they were made with, and + /// why: a request of that index (the file as it was) asking for at /// least as much fails the same way until the file is forgotten. - failed: Vec<(Want, Refused)>, + failed: Vec<(Arc, Want, Refused)>, bytes: usize, /// When it was last asked for or finished decoding ([`effectcraft_render::memory::tick`]). used: u64, @@ -504,7 +505,8 @@ impl PlaneStore { crate::reads::note(b.file.clone()); return Step::Done(Ok(b)); } - if let Some((_, why)) = e.failed.iter().find(|(failed, _)| asks_at_least(want, failed)) { + // (a failure of the file as it was before: the file changed since, it is read again) + if let Some((_, _, why)) = e.failed.iter().find(|(of, failed, _)| Arc::ptr_eq(of, index) && asks_at_least(want, failed)) { return Step::Done(Err(why.clone())); } if let Some(flight) = e.flight.clone() { @@ -641,11 +643,16 @@ impl PlaneStore { e.batch = Some(b.clone()); } Err(why @ (Refused::Unreadable | Refused::TooLarge(_))) => { - let want = flight.state().want.clone(); + let (index, want) = { + let fs = flight.state(); + (fs.index.clone(), fs.want.clone()) + }; + // (failures of another version of the file no longer apply) + e.failed.retain(|(of, _, _)| Arc::ptr_eq(of, &index)); if e.failed.len() >= FAILED_KEPT { e.failed.remove(0); } - e.failed.push((want, why.clone())); + e.failed.push((index, want, why.clone())); } // (the file changed: what is held is of the old one) Err(Refused::Changed) => { diff --git a/crates/media/src/exr_planes/tests.rs b/crates/media/src/exr_planes/tests.rs index 47b533ea6..55b80acf5 100644 --- a/crates/media/src/exr_planes/tests.rs +++ b/crates/media/src/exr_planes/tests.rs @@ -1382,3 +1382,26 @@ fn the_picture_planes_are_not_kept_beside_the_picture() { assert!(shared().kept(path).is_none()); forget(path); } + +/// #3271 review (#3301): a remembered failure belongs to the file as it was. A file that was +/// unreadable and is then replaced on disk (no Reload Footage: the new index comes from its new +/// stamp) is read again, not refused with the old file's failure. +#[test] +fn a_failure_is_forgotten_once_the_file_changes() { + let good: Arc<[u8]> = write(vec![part(None, &RGBA, (8, 8), Compression::ZIP1)], (8, 8)).into(); + let mut broken = good.to_vec(); + broken.truncate(broken.len() - 64); + let path = "/3271-failed-then-fixed.exr"; + let store = PlaneStore::new(CACHE_BUDGET); + let all = Want { all: true, ids: (0..4).collect() }; + let source = ExrSource::Bytes(broken.into()); + let old = crate::exr_index::get(path, &source).unwrap(); + assert!(store.get(path, &source, &old, &all, Use::Other).is_err()); + assert!(store.get(path, &source, &old, &all, Use::Other).is_err(), "remembered for the same file"); + // The file is replaced: another index (here read under another name, as the file's new stamp + // would give it). + let source = ExrSource::Bytes(good); + let new = crate::exr_index::get("/3271-failed-then-fixed-new.exr", &source).unwrap(); + assert!(!Arc::ptr_eq(&old, &new)); + assert!(store.get(path, &source, &new, &all, Use::Other).is_ok(), "the new file is read"); +}