mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Placed documents: a bitmap made on the drawing thread stops being pending when it panics
Where no background worker starts (and on the web), schedule makes the bitmap on the drawing thread. A panic there left the bitmap pending, so wait_idle, which has no time limit, could wait for it forever. That path now does what the worker does after a panic: it marks the bitmap failed and stops it being pending, then lets the panic go on to the caller.
This commit is contained in:
1 parent
3d88485fa6
commit
0ab27fdc73
2 files changed
+42
-1
No files matched your search
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user