Refuse an automation capture while the window is minimized

A minimized window has a 0x0 surface; the renderer's screenshot path
panicked on the empty read-back buffer and took the whole application
down. The capture op now checks the window size first and answers with
an error instead of requesting the screenshot.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
ramox81andClaude Fable 5.1 committed 2026-09-18 20:36:08 +03:00
1 parent a7ab5314f2
commit 02a75ead50
1 file changed
+13 -3
+13 -3
View File
@@ -866,8 +866,17 @@ impl OpenCADStudio {
.main_window
.ok_or_else(|| failure("gui_required", "Capture requires a GUI window"))?;
let path = string(req, "path")?.to_owned();
iced::window::screenshot(window)
.map(move |s| Message::ControlScreenshot(path.clone(), Some(s)))
// A minimized window has a 0x0 surface and the renderer
// panics reading it back, so report instead of capturing.
iced::window::size(window).then(move |size| {
let path = path.clone();
if size.width <= 0.0 || size.height <= 0.0 {
Task::done(Message::ControlScreenshot(path, None))
} else {
iced::window::screenshot(window)
.map(move |s| Message::ControlScreenshot(path.clone(), Some(s)))
}
})
}
"stop" => {
self.control.enabled = false;
@@ -1062,7 +1071,8 @@ impl OpenCADStudio {
screenshot: Option<iced::window::Screenshot>,
) {
let result = (|| -> Result<Value, String> {
let s = screenshot.ok_or("Renderer did not return an image")?;
let s = screenshot
.ok_or("The window is minimized or has no size; restore it and capture again")?;
let requested_scope = self
.control
.pending