Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion tiny_skia/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use tiny_skia::Transform;
use std::cell::RefCell;
use std::collections::hash_map;
use std::fs;
use std::panic;
use std::sync::Arc;

#[derive(Debug)]
Expand Down Expand Up @@ -168,7 +169,15 @@ impl Cache {
tiny_skia::Transform::default()
};

resvg::render(tree, transform, &mut image.as_mut());
// SVG rendering can panic on malformed or complex vectors.
// We catch panics to prevent crashes and continue gracefully.
let render = panic::catch_unwind(panic::AssertUnwindSafe(|| {
resvg::render(tree, transform, &mut image.as_mut());
}));

if let Err(error) = render {
log::warn!("SVG rendering for {handle:?} panicked: {error:?}");
}

if let Some([r, g, b, _]) = key.color {
// Apply color filter
Expand Down
14 changes: 13 additions & 1 deletion wgpu/src/image/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use resvg::tiny_skia;
use resvg::usvg;
use rustc_hash::{FxHashMap, FxHashSet};
use std::fs;
use std::panic;
use std::sync::Arc;

/// Entry in cache corresponding to an svg handle
Expand Down Expand Up @@ -154,7 +155,18 @@ impl Cache {
tiny_skia::Transform::default()
};

resvg::render(tree, transform, &mut img.as_mut());
// SVG rendering can panic on malformed or complex vectors.
// We catch panics to prevent crashes and continue gracefully.
let render =
panic::catch_unwind(panic::AssertUnwindSafe(|| {
resvg::render(tree, transform, &mut img.as_mut());
}));

if let Err(error) = render {
log::warn!(
"SVG rendering for {handle:?} panicked: {error:?}"
);
}

let mut rgba = img.take();

Expand Down
Loading