iced-rs/iced · error
Non-zero width
Error message
Non-zero width
What it means
configure_surface resizes the softbuffer surface, whose API requires NonZeroU32 dimensions; iced converts with NonZeroU32::new(width).expect("Non-zero width"), which panics when width == 0. Inside create_surface the call is guarded by width > 0 && height > 0 (compositor.rs:71), and iced_winit skips configuration when the physical size is zero (winit/src/lib.rs:759-761), so the panic is only reachable when the Compositor trait is driven directly with a zero width.
Solutions
- Guard the call exactly like the stock runtime: skip configure_surface when width or height is 0
- Clamp dimensions to at least 1 pixel if a resize must always be applied
- If you maintain the integration, map zero sizes to a no-op instead of letting the expect fire
Example fix
// before
compositor.configure_surface(&mut surface, size.width, size.height);
// after
if size.width > 0 && size.height > 0 {
compositor.configure_surface(&mut surface, size.width, size.height);
} Defensive patterns
Strategy: validation
Validate before calling
// Before configuring a surface in a custom runtime:
fn is_configurable(size: (u32, u32)) -> bool {
size.0 > 0 && size.1 > 0
}
if is_configurable((physical.width, physical.height)) {
compositor.configure_surface(&mut surface, physical.width, physical.height);
} Prevention
- Mirror iced_winit's guard: it skips configuration whenever physical width or height is 0 (winit/src/lib.rs:759)
- Never forward raw inner_size() values from minimized windows to the compositor
When it happens
Trigger: Embedding iced_tiny_skia's Compositor directly and calling configure_surface(&mut surface, 0, height); a custom winit event loop that forwards a minimized window's 0x0 resize straight to configure_surface without the guard the stock runtime has; reading window.inner_size() before the first layout completes.
Common situations: Custom shells and runtime integrations built on iced_tiny_skia/iced_winit primitives; test harnesses driving the compositor headlessly; platforms that report 0x0 while a window is minimized or hidden.
Related errors
- Non-zero height
- Create pixel map
- Create softbuffer context
- Create softbuffer surface for window
- Create clip mask
AI-assisted analysis of iced-rs/iced@3de451447b (2026-08-17).
Data as JSON: /api/errors/fb1d4a32620bacf4.
Report an issue: GitHub.
Appendix: source
Thrown at tiny_skia/src/window/compositor.rs:82
let mut surface = Surface {
window,
clip_mask: tiny_skia::Mask::new(1, 1).expect("Create clip mask"),
frames: VecDeque::new(),
max_age: 0,
};
if width > 0 && height > 0 {
self.configure_surface(&mut surface, width, height);
}
surface
}
fn configure_surface(&mut self, surface: &mut Self::Surface, width: u32, height: u32) {
surface
.window
.resize(
NonZeroU32::new(width).expect("Non-zero width"),
NonZeroU32::new(height).expect("Non-zero height"),
)
.expect("Resize surface");
surface.clip_mask = tiny_skia::Mask::new(width, height).expect("Create clip mask");
surface.frames.clear();
}
fn information(&self) -> Information {
Information {
adapter: String::from("CPU"),
backend: String::from("tiny-skia"),
}
}
fn present(
&mut self,
renderer: &mut Self::Renderer,View on GitHub (pinned to 3de451447b)