Merge pull request #50 from smittie2000/fix/no-desktop-start

fix(windows): a window that can't start says why instead of the app exiting silently
This commit is contained in:
Rafael Mendes authored and GitHub committed 2026-11-05 12:01:47 -03:00
commit a5f298299d
4 files changed
+58

No files matched your search

Generated
+1
View File
@@ -2316,6 +2316,7 @@ dependencies = [
"materialcraft-automation",
"materialcraft-engine",
"materialcraft-ui-egui",
"rfd",
"serde_json",
"winresource",
]
+2
View File
@@ -19,6 +19,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"
+3
View File
@@ -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;
@@ -109,6 +110,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);
}
}
+52
View File
@@ -0,0 +1,52 @@
//! 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. 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 {
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.
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 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 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}");
}
}