-
Notifications
You must be signed in to change notification settings - Fork 289
fix: change assert!() to Result with Error
#1008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for jumping on this so quickly! I noticed that the the comments also have the following, which can be removed: /// # Panics
///
/// When `src1`, `src2` and `dest` have different sizes.
|
Good catch Note that my PR doesn't not means a merge, since it needs to be reviewed ^^ Note: Plz merge before |
assert to Result with Error
assert to Result with Errorassert!() to Result with Error
|
In case maintaining API compatibility is important, it would be viable to have 2 variants of the fn:
That being said, I can't imagine a use-case where resvg is used as a library, and the developer would want it to panic depending on a faulty input file. |
|
If there is a panic in filters code it means we have parsed the SVG wrong. Therefore fixing the filters code is band-aid. |
|
i have submitted an SVG that triggers this in #1007 |
|
the filter bounding box sizing looks suspicious. <filter
id="point-light-filter-0"
primitiveUnits="objectBoundingBox"
x="-500%"
y="-500%"
width="1000%"
height="1000%"
bx:preset="point-light
1 0.5 0.5 0.5 50 1 0.2 0 #ffffff"> |
I agree that fixing bugs to have a correct parser and rendered is the good thing to do. But penalizing crates which uses resvg by allowing it to panic is not great for a library I think the problem #1007 is not from the parsing but from this part // crates/resvg/src/lib.rs
let target_size = tiny_skia::IntSize::from_wh(pixmap.width(), pixmap.height()).unwrap();
let max_bbox = tiny_skia::IntRect::from_xywh(
-(target_size.width() as i32) * 2,
-(target_size.height() as i32) * 2,
target_size.width() * 5,
target_size.height() * 5,
)
.unwrap();If I increase the |
|
Agree that we should remove asserts as well, but they are not the reason why this code fails. I.e. this issue need two fixes. As for 2 and 5 - this is to limit the filter region to 5x the size. The limit is arbitrary. |
Shouldn't this limit be set by the user using options args/params ? (kinda linked to #815) For example, if I change the size like in my latest commits, the render is working `main()` codefn main() {
if let Ok(()) = log::set_logger(&LOGGER) {
log::set_max_level(log::LevelFilter::Warn);
}
let width = 96;
let height = 96;
let file_path = "534586290-631255f5-efc4-40bf-966e-69d08a6d3d48.svg"; // downloaded from the issue
let options = resvg::usvg::Options {
style_sheet: Some("svg { color: white }".into()),
..Default::default()
};
let data = std::fs::read(file_path).unwrap();
let tree = resvg::usvg::Tree::from_data(data.as_slice(), &options).unwrap();
let svg_size = tree.size();
let scale_x = (width as f32) / svg_size.width();
let scale_y = (height as f32) / svg_size.height();
println!("{width} {height}");
let mut pixmap = resvg::tiny_skia::Pixmap::new(width as _, height as _).unwrap();
let transform = resvg::usvg::Transform::from_scale(scale_x, scale_y);
resvg::render(&tree, transform, &mut pixmap.as_mut());
let buf = pixmap.encode_png().map_err(|e| e.to_string()).unwrap();
std::fs::write("a.png", &buf).unwrap();
} |
|
It's such a rare edge case that it's not important. |
fix #1007
The CLI will produce