Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Merge storytold/main into fix/2678-failed-thumb-retries

insideTheFlux932aae1f7142
diff --cc crates/ui-egui/src/render/thumbnail_tests.rs
index f126bd396,eaf4e8f2f..43c200d57
--- a/crates/ui-egui/src/render/thumbnail_tests.rs
+++ b/crates/ui-egui/src/render/thumbnail_tests.rs
@@@ -164,55 -188,36 +188,85 @@@ fn failures_retry_after_revision_and_qu
assert!(!r.thumb_current(&p, 384, 10));
}
+ /// A larger texture only serves a smaller bucket when it is the recorded request's picture.
+ /// This isolates the key guard: under a `contains_key`-only check the first assertion below
+ /// would return `true`.
+ #[test]
+ fn larger_texture_for_another_key_does_not_count_as_current() {
+ let p = photo();
+ let slot = Slot::Thumb(p.id);
+ let ctx = egui::Context::default();
+ let tex = |key| Tex {
+ look: None,
+ key,
+ photo: p.id,
+ tex: ctx.load_texture(format!("thumb-{key}"), egui::ColorImage::new([1, 1], vec![egui::Color32::BLACK]), Default::default()),
+ size: [1, 1],
+ histogram: None,
+ ms: 0.0,
+ quick: None,
+ pixels: None,
+ };
+ let mut r = Renderer::default();
+ // A completed larger bucket: the remembered request is bucket 512, key 77.
+ r.remember_thumb(&p, 512, 77, false, 10);
+ // Another key's pixels (for example the picture from before an edit) may still be
+ // displayed, but they are not the remembered request's picture.
+ r.textures.insert(slot, tex(66));
+ assert!(!r.thumb_current(&p, 256, 10), "a mismatched texture key must not serve a smaller bucket");
+ r.textures.insert(slot, tex(77));
+ assert!(r.thumb_current(&p, 256, 10), "the recorded key's larger texture serves the smaller bucket");
+ }
+
+/// Issue #2682: writes to other photos in the background (faces found, metadata read) moved
+/// the catalog revision on and sent every undecodable file back to the decoder, 37 times each
+/// in 154 s of idle. A failure is tried again only when its own photo changes, when the
+/// catalog can't say which photos did, or, at any change, when its file is known to be missing.
+#[test]
+fn a_failed_thumbnail_is_retried_only_when_its_photo_changes() {
+ use std::sync::atomic::{AtomicBool, Ordering};
+ let mut catalog = Catalog::default();
+ let p = photo();
+ let other = PhotoId(2);
+ catalog.apply(Op::AddPhoto { photo: Box::new((*p).clone()) }).unwrap();
+ let other_photo = Photo::new(other, Source::File { path: "other.jpg".into() }, "other.jpg", "JPEG", 60, 40, "2026-01-01");
+ catalog.apply(Op::AddPhoto { photo: Box::new(other_photo) }).unwrap();
+ // the files are there (an undecodable file is still a file)
+ let here = Arc::new(AtomicBool::new(true));
+ let mut files = lightcraft_engine::availability::Availability::default();
+ let h = here.clone();
+ files.set_probe(Arc::new(move |_| h.load(Ordering::SeqCst)));
+ let slot = Slot::Thumb(p.id);
+ let mut r = Renderer::default();
+ r.follow_catalog(&catalog, &files);
+ r.failed.insert(slot, (77, "unrecognised image format".into(), r.catalog_rev, p.id));
+ assert!(!r.request_needed(slot, 77, 10), "a failure stands");
+ // the other photo changes, op after op, as background work does
+ for rating in 1..=5 {
+ catalog.apply(Op::SetRating { id: other, rating }).unwrap();
+ r.follow_catalog(&catalog, &files);
+ assert!(!r.request_needed(slot, 77, 10), "another photo's change (rating {rating}) retries nothing");
+ }
+ // a change to the photo itself is a reason to try again
+ catalog.apply(Op::SetRating { id: p.id, rating: 2 }).unwrap();
+ r.follow_catalog(&catalog, &files);
+ assert!(r.request_needed(slot, 77, 10), "its own photo changed");
+ // so is a change the catalog can't attribute to photos
+ r.failed.insert(slot, (77, "unrecognised image format".into(), r.catalog_rev, p.id));
+ assert!(!r.request_needed(slot, 77, 10));
+ let album = catalog.alloc_album_id();
+ catalog.apply(Op::AddAlbum { album: lightcraft_catalog::Album::new(album, "Trip") }).unwrap();
+ r.follow_catalog(&catalog, &files);
+ assert!(r.request_needed(slot, 77, 10), "which photos changed is unknown");
+ // a file known to be missing (its drive unplugged) is tried at every change, as before, so
+ // the photo comes back with its drive
+ r.failed.insert(slot, (77, "file not found".into(), r.catalog_rev, p.id));
+ here.store(false, Ordering::SeqCst);
+ catalog.apply(Op::SetRating { id: other, rating: 1 }).unwrap();
+ r.follow_catalog(&catalog, &files);
+ assert!(r.request_needed(slot, 77, 10), "a missing file is tried again");
+}
+
#[test]
fn a_fast_draft_is_drawn_in_the_frame_that_asked_for_it() {
let mut s = Session::new();