Merge pull request #9917 from dotCooCoo/fix/placed-document-inline-panic

Placed documents: a bitmap made on the drawing thread stops being pending when it panics
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-28 08:03:04 -08:00
commit bc28d7da82
2 files changed
+42 -1

No files matched your search

+27 -1
View File
@@ -496,7 +496,33 @@ fn schedule(job: Job) {
Ok(()) => return,
Err(job) => *job,
};
run(&mut Renderer::new(), job);
run_here(job);
}
/// [`run`] `job` on this thread. When it panics, its bitmap failed (it is not asked for again)
/// and stops being pending, and the panic goes on to the caller.
fn run_here(job: Job) {
let key = job.key.clone();
if let Err(panic) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| run(&mut Renderer::new(), job))) {
lock(&FAILED).insert(key.clone());
finish(&key);
std::panic::resume_unwind(panic);
}
}
/// Make the bitmap of `object`'s file (`blob`) at zoom `step` on this thread, as [`schedule`]
/// does where no worker starts, inside `scope`.
#[cfg(test)]
pub(crate) fn make_here(object: &PlacedDocument, blob: ImageBlob, step: f64, scope: Scoped) {
let key = (object.key.clone(), step.to_bits(), false);
lock(&PENDING).insert(key.clone());
run_here(Job { key, object: object.clone(), blob, step, keep: 0, scope: Some(scope) });
}
/// Could a bitmap of file `key` not be made?
#[cfg(test)]
pub(crate) fn failed_for(key: &str) -> bool {
lock(&FAILED).iter().any(|k| k.0 == key)
}
/// The file `p` shows (its bytes `blob`) read as art, and kept for
@@ -557,6 +557,21 @@ fn on_screen_a_placed_document_shows_a_placeholder_then_its_bitmap() {
}
}
#[test]
fn a_bitmap_that_panics_while_made_on_the_drawing_thread_stops_being_pending() {
let _serial = serial();
let d = doc("inline-panic-1");
let Some(NodeKind::PlacedDocument(p)) = d.node(NodeId(50)).map(|n| &n.kind) else { panic!("a placed document") };
let Some(blob) = d.images.get("inline-panic-1") else { panic!("the file's bytes") };
let made = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
placed_document::make_here(p, blob.clone(), 1.0, Box::new(|_| panic!("the job fails")));
}));
assert!(made.is_err(), "the panic reaches the caller");
assert!(!placed_document::pending_for("inline-panic-1"), "nothing waits for the bitmap");
assert!(placed_document::failed_for("inline-panic-1"), "and it is not asked for again");
settle();
}
#[test]
fn copies_of_one_placed_document_share_its_bitmap() {
let _serial = serial();