From c9e3a9ea837eb51ab19cbedf0d03a0072fa57ee2 Mon Sep 17 00:00:00 2001 From: smittie2000 Date: Tue, 3 Nov 2026 22:55:23 +0200 Subject: [PATCH 1/3] fix(windows): a start that never opens a window says why instead of exiting silently Without a usable GPU, driver or desktop, no graphics backend can create a window and MaterialCraft exited with code 1 and nothing on screen. The reason now goes to the log and to an error dialog, as FilmCraft does since 0.14.0 (which unstuck it on WinGet). Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 1 + apps/materialcraft/Cargo.toml | 2 ++ apps/materialcraft/src/main.rs | 3 +++ apps/materialcraft/src/start_failure.rs | 36 +++++++++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 apps/materialcraft/src/start_failure.rs diff --git a/Cargo.lock b/Cargo.lock index ce3b0fc1..2cf4cdaa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2315,6 +2315,7 @@ dependencies = [ "log", "materialcraft-engine", "materialcraft-ui-egui", + "rfd", "serde_json", "winresource", ] diff --git a/apps/materialcraft/Cargo.toml b/apps/materialcraft/Cargo.toml index 64a1ca49..d5783b90 100644 --- a/apps/materialcraft/Cargo.toml +++ b/apps/materialcraft/Cargo.toml @@ -18,6 +18,8 @@ egui = { workspace = true } image = { workspace = true } serde_json = { workspace = true } log = { workspace = true } +# A start that never opens a window says why in an error dialog (src/start_failure.rs). +rfd = { workspace = true } [build-dependencies] winresource = "0.1" diff --git a/apps/materialcraft/src/main.rs b/apps/materialcraft/src/main.rs index 5a27232c..781e79d0 100644 --- a/apps/materialcraft/src/main.rs +++ b/apps/materialcraft/src/main.rs @@ -6,6 +6,7 @@ #![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)] mod control_server; +mod start_failure; use materialcraft_engine::Session; use materialcraft_ui_egui::MaterialCraftApp; @@ -118,6 +119,8 @@ fn main() { ); if let Err(e) = r { eprintln!("materialcraft: {e}"); + // Say why instead of exiting silently (`start_failure`). + start_failure::report(&e); std::process::exit(1); } } diff --git a/apps/materialcraft/src/start_failure.rs b/apps/materialcraft/src/start_failure.rs new file mode 100644 index 00000000..836ae6ba --- /dev/null +++ b/apps/materialcraft/src/start_failure.rs @@ -0,0 +1,36 @@ +//! A window that can't start, or stops, says why instead of the app quitting silently. +//! +//! Without a usable GPU, graphics driver or desktop (a broken or very old driver, a remote or +//! virtual machine, a program started by a service or a test harness), the window's surface +//! can't be configured and eframe returns an error. MaterialCraft used to log it and exit with no +//! window, which looks like "the app doesn't open". +//! winget-pkgs validation starts installed programs without a desktop, so a version that fails +//! like this never reaches WinGet. +//! +//! Now the reason also goes to an error dialog, as FilmCraft does since 0.14.0. The dialog keeps +//! the process alive until it is dismissed; the exit code afterwards is still the error's. + +/// What the dialog and the log say. +pub(crate) fn message(error: &eframe::Error) -> String { + format!("MaterialCraft could not start its window: {error}\n\nUpdating the graphics driver usually fixes this.") +} + +/// Logs the failure and shows it in a dialog, which stays until the user closes it. +pub(crate) fn report(error: &eframe::Error) { + let message = message(error); + log::error!("{message}"); + let _ = rfd::MessageDialog::new().set_title("MaterialCraft").set_description(&message).set_level(rfd::MessageLevel::Error).show(); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn the_message_names_the_cause_and_what_to_do() { + let text = message(&eframe::Error::AppCreation("no adapter".into())); + assert!(text.starts_with("MaterialCraft could not start its window"), "{text}"); + assert!(text.contains("no adapter"), "{text}"); + assert!(text.contains("graphics driver"), "{text}"); + } +} From 6f73fc7c7745db317ff5c36b432dc13fbdf2350f Mon Sep 17 00:00:00 2001 From: smittie2000 Date: Wed, 4 Nov 2026 06:50:35 +0200 Subject: [PATCH 2/3] start_failure: say the window could not start or stopped, and offer the driver as a likely fix The dialog is shown for any error run_native returns, including one after the window was up, so "could not start its window" and "updating the graphics driver usually fixes this" overstated what is known. From review. Co-Authored-By: Claude Opus 5.5 --- apps/materialcraft/src/start_failure.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/materialcraft/src/start_failure.rs b/apps/materialcraft/src/start_failure.rs index 836ae6ba..5552e0f0 100644 --- a/apps/materialcraft/src/start_failure.rs +++ b/apps/materialcraft/src/start_failure.rs @@ -10,9 +10,10 @@ //! Now the reason also goes to an error dialog, as FilmCraft does since 0.14.0. The dialog keeps //! the process alive until it is dismissed; the exit code afterwards is still the error's. -/// What the dialog and the log say. +/// What the dialog and the log say. Any error `run_native` returns lands here, also one after the +/// window was up, so graphics is only the likely cause, not the certain one. pub(crate) fn message(error: &eframe::Error) -> String { - format!("MaterialCraft could not start its window: {error}\n\nUpdating the graphics driver usually fixes this.") + format!("MaterialCraft's window could not start or stopped with an error: {error}\n\nIf this keeps happening, updating the graphics driver often fixes it.") } /// Logs the failure and shows it in a dialog, which stays until the user closes it. @@ -29,7 +30,7 @@ mod tests { #[test] fn the_message_names_the_cause_and_what_to_do() { let text = message(&eframe::Error::AppCreation("no adapter".into())); - assert!(text.starts_with("MaterialCraft could not start its window"), "{text}"); + assert!(text.starts_with("MaterialCraft's window could not start or stopped"), "{text}"); assert!(text.contains("no adapter"), "{text}"); assert!(text.contains("graphics driver"), "{text}"); } From 5a7fe7b6b6c7fbe03d8a8188533acf6d831425e2 Mon Sep 17 00:00:00 2001 From: smittie2000 Date: Wed, 4 Nov 2026 14:17:30 +0200 Subject: [PATCH 3/3] start_failure: an app start-up error doesn't blame the graphics From CodeRabbit: an error from the app creator (AppCreation, e.g. a --control file it can't write) comes after the window and renderer started, so "update the graphics driver" doesn't apply. It now says only that the app couldn't start; other errors keep the window/graphics text. Tested both ways (the new test fails with the AppCreation arm disabled). Co-Authored-By: Claude Opus 5.5 --- apps/materialcraft/src/start_failure.rs | 27 +++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/apps/materialcraft/src/start_failure.rs b/apps/materialcraft/src/start_failure.rs index 5552e0f0..17596045 100644 --- a/apps/materialcraft/src/start_failure.rs +++ b/apps/materialcraft/src/start_failure.rs @@ -10,10 +10,17 @@ //! Now the reason also goes to an error dialog, as FilmCraft does since 0.14.0. The dialog keeps //! the process alive until it is dismissed; the exit code afterwards is still the error's. -/// What the dialog and the log say. Any error `run_native` returns lands here, also one after the -/// window was up, so graphics is only the likely cause, not the certain one. +/// What the dialog and the log say. Any error `run_native` returns lands here. One from the app's +/// own start-up (`AppCreation`, e.g. a `--control` file it can't write) says only that it couldn't +/// start. Any other comes from the window or graphics, possibly after the window was up, so +/// graphics is named as the likely cause, not the certain one. pub(crate) fn message(error: &eframe::Error) -> String { - format!("MaterialCraft's window could not start or stopped with an error: {error}\n\nIf this keeps happening, updating the graphics driver often fixes it.") + match error { + eframe::Error::AppCreation(_) => format!("MaterialCraft could not start: {error}"), + _ => format!( + "MaterialCraft's window could not start or stopped with an error: {error}\n\nIf this keeps happening, updating the graphics driver often fixes it." + ), + } } /// Logs the failure and shows it in a dialog, which stays until the user closes it. @@ -28,10 +35,18 @@ mod tests { use super::*; #[test] - fn the_message_names_the_cause_and_what_to_do() { - let text = message(&eframe::Error::AppCreation("no adapter".into())); + fn a_window_or_graphics_error_names_the_driver_as_the_likely_fix() { + let text = message(&eframe::Error::Wgpu(eframe::egui_wgpu::WgpuError::NoSurfaceFormatsAvailable)); assert!(text.starts_with("MaterialCraft's window could not start or stopped"), "{text}"); - assert!(text.contains("no adapter"), "{text}"); + assert!(text.contains("no valid format for the surface"), "{text}"); assert!(text.contains("graphics driver"), "{text}"); } + + #[test] + fn an_app_start_up_error_does_not_blame_the_graphics() { + let text = message(&eframe::Error::AppCreation("can't write the control file".into())); + assert!(text.starts_with("MaterialCraft could not start"), "{text}"); + assert!(text.contains("can't write the control file"), "{text}"); + assert!(!text.contains("graphics"), "{text}"); + } }