Try to render corrupt SVGs after panic
This commit is contained in:
parent
d845ac27db
commit
4cc7eb47f7
2 changed files with 12 additions and 17 deletions
|
|
@ -7,7 +7,8 @@ use tiny_skia::Transform;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::hash_map;
|
use std::collections::hash_map;
|
||||||
use std::{fs, panic};
|
use std::fs;
|
||||||
|
use std::panic;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -170,17 +171,12 @@ impl Cache {
|
||||||
|
|
||||||
// SVG rendering can panic on malformed or complex vectors.
|
// SVG rendering can panic on malformed or complex vectors.
|
||||||
// We catch panics to prevent crashes and continue gracefully.
|
// We catch panics to prevent crashes and continue gracefully.
|
||||||
let render_result =
|
let render = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||||
panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
resvg::render(tree, transform, &mut image.as_mut());
|
||||||
resvg::render(tree, transform, &mut image.as_mut());
|
}));
|
||||||
}));
|
|
||||||
|
|
||||||
if render_result.is_err() {
|
if let Err(error) = render {
|
||||||
log::warn!(
|
log::warn!("SVG rendering for {handle:?} panicked: {error:?}");
|
||||||
"SVG rendering panicked for handle ID: {}",
|
|
||||||
handle.id()
|
|
||||||
);
|
|
||||||
return None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some([r, g, b, _]) = key.color {
|
if let Some([r, g, b, _]) = key.color {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ use crate::image::atlas::{self, Atlas};
|
||||||
use resvg::tiny_skia;
|
use resvg::tiny_skia;
|
||||||
use resvg::usvg;
|
use resvg::usvg;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use std::{fs, panic};
|
use std::fs;
|
||||||
|
use std::panic;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// Entry in cache corresponding to an svg handle
|
/// Entry in cache corresponding to an svg handle
|
||||||
|
|
@ -156,17 +157,15 @@ impl Cache {
|
||||||
|
|
||||||
// SVG rendering can panic on malformed or complex vectors.
|
// SVG rendering can panic on malformed or complex vectors.
|
||||||
// We catch panics to prevent crashes and continue gracefully.
|
// We catch panics to prevent crashes and continue gracefully.
|
||||||
let render_result =
|
let render =
|
||||||
panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||||
resvg::render(tree, transform, &mut img.as_mut());
|
resvg::render(tree, transform, &mut img.as_mut());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if render_result.is_err() {
|
if let Err(error) = render {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"SVG rendering panicked for handle ID: {}",
|
"SVG rendering for {handle:?} panicked: {error:?}"
|
||||||
handle.id()
|
|
||||||
);
|
);
|
||||||
return None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut rgba = img.take();
|
let mut rgba = img.take();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue