From 50026c5e49c9f467238aba0f135996c11e029477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eleazar=20D=C3=ADaz=20Delgado?= Date: Thu, 6 Mar 2025 12:48:37 +0000 Subject: [PATCH] Fix error on chromium like browser when canvas initial size (0,0) Co-authored-by: EleDiaz --- tiny_skia/src/window/compositor.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tiny_skia/src/window/compositor.rs b/tiny_skia/src/window/compositor.rs index b7511d71..c77210b9 100644 --- a/tiny_skia/src/window/compositor.rs +++ b/tiny_skia/src/window/compositor.rs @@ -66,16 +66,26 @@ impl crate::graphics::Compositor for Compositor { ) .expect("Create softbuffer surface for window"); + let clip_mask = { + if width > 0 && height > 0 { + tiny_skia::Mask::new(width, height) + } else { + tiny_skia::Mask::new(1, 1) + } + } + .expect("Create clip mask"); + let mut surface = Surface { window, - clip_mask: tiny_skia::Mask::new(width, height) - .expect("Create clip mask"), + clip_mask, layer_stack: VecDeque::new(), background_color: Color::BLACK, max_age: 0, }; - self.configure_surface(&mut surface, width, height); + if width > 0 && height > 0 { + self.configure_surface(&mut surface, width, height); + } surface }