diff --git a/Cargo.lock b/Cargo.lock index 49210cf2..bd63ffd0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3818,6 +3818,7 @@ dependencies = [ "egui", "image", "log", + "rfd", "ron", "serde_json", "texturecraft-automation", diff --git a/README.md b/README.md index b9772d80..fb99bc07 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,11 @@ Japanese, Chinese, Korean and Arabic interface text uses the fonts of build input (releases always use it): `CRAFT_FONTS_DIR="$PWD/../craft-fonts" cargo run --release -p texturecraft` (an absolute path). Without it, the desktop app uses the installed system fonts. +If the app cannot start (no usable GPU, say) or has to close, it says why in a message box and +appends the details to `errors.log` beside its settings (`%APPDATA%\TextureCraft\data` on Windows, +`~/Library/Application Support/TextureCraft` on macOS, `~/.local/share/texturecraft` on Linux). +On a machine with several GPUs, `--gpu ` or `--power-pref high` picks one. + ### Use it from Claude Code and other agents Register the MCP server with Claude Code, giving it the folders it may read and write: diff --git a/apps/texturecraft/Cargo.toml b/apps/texturecraft/Cargo.toml index 581b2eb0..2f80d416 100644 --- a/apps/texturecraft/Cargo.toml +++ b/apps/texturecraft/Cargo.toml @@ -20,6 +20,8 @@ egui = { workspace = true } image = { workspace = true } serde_json = { workspace = true } log = { workspace = true } +# The message box for errors that end the app (a Windows release build has no console). +rfd = { workspace = true } # Reads the saved System title bar setting before the window opens (eframe's settings format). ron = "0.12" diff --git a/apps/texturecraft/src/main.rs b/apps/texturecraft/src/main.rs index 42b56ba4..377b2e52 100644 --- a/apps/texturecraft/src/main.rs +++ b/apps/texturecraft/src/main.rs @@ -170,9 +170,12 @@ fn main() { std::process::exit(2); } }; + // Errors before the window opens speak the system's language; the app then applies the saved one. + texturecraft_ui_egui::i18n::set_language(texturecraft_ui_egui::i18n::os_language()); let prev = std::panic::take_hook(); std::panic::set_hook(Box::new(move |info| { - eprintln!("texturecraft: internal error: {info}"); + // A message box needs the main thread on macOS; other threads' panics are only logged. + fatal(&format!("internal error: {info}"), std::thread::current().name() == Some("main")); prev(info); })); let session = initial_session(&args); @@ -188,7 +191,7 @@ fn main() { let viewport = title_bar.viewport(viewport); let mut options = eframe::NativeOptions { viewport, renderer: eframe::Renderer::Wgpu, persistence_path, ..Default::default() }; if let Err(e) = gpu::configure(&mut options, args.gpu, args.power_pref) { - eprintln!("texturecraft: {e}"); + fatal(&e.to_string(), true); std::process::exit(2); } let control = args.control; @@ -218,11 +221,41 @@ fn main() { }), ); if let Err(e) = r { - eprintln!("texturecraft: {e}"); + fatal(&e.to_string(), true); std::process::exit(1); } } +/// The file startup errors and crashes are appended to, beside the saved settings. +fn error_log() -> Option { + eframe::storage_dir(APP_NAME).map(|d| d.join("errors.log")) +} + +/// Append a line with the time (Unix seconds) and the app version; true when it was written. +fn append_line(file: &std::path::Path, msg: &str) -> bool { + use std::io::Write as _; + let secs = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_or(0, |d| d.as_secs()); + let open = || std::fs::OpenOptions::new().create(true).append(true).open(file); + file.parent().is_some_and(|d| std::fs::create_dir_all(d).is_ok()) && open().and_then(|mut f| writeln!(f, "[{secs}] {}: {msg}", version())).is_ok() +} + +/// An error that ends the app: printed, logged, and (with `dialog`) shown in a message box, since +/// a Windows release build has no console and would otherwise close without a word. +fn fatal(msg: &str, dialog: bool) { + eprintln!("texturecraft: {msg}"); + let log = error_log().filter(|f| append_line(f, msg)); + if dialog { + use texturecraft_ui_egui::i18n::{tr, trf}; + let saved = log.map(|f| format!("\n\n{}", trf("Details saved to {file}", &[("file", &f.display())]))).unwrap_or_default(); + rfd::MessageDialog::new() + .set_level(rfd::MessageLevel::Error) + .set_title(APP_NAME) + .set_description(format!("{}\n\n{msg}{saved}", tr("TextureCraft had to close:"))) + .set_buttons(rfd::MessageButtons::Ok) + .show(); + } +} + #[cfg(test)] mod tests { use super::*; @@ -248,6 +281,20 @@ mod tests { assert!(parse_args_from(["--power-pref".to_string(), "unrecognized".to_string()]).is_err()); } + #[test] + fn errors_are_appended_to_the_log_in_a_new_folder() { + let dir = std::env::temp_dir().join(format!("texturecraft-errlog-test-{}", std::process::id())); + let file = dir.join("nested").join("errors.log"); + assert!(append_line(&file, "first")); + assert!(append_line(&file, "second")); + let text = std::fs::read_to_string(&file).unwrap(); + let lines: Vec<&str> = text.lines().collect(); + assert_eq!(lines.len(), 2); + assert!(lines[0].ends_with(&format!("{}: first", version())) && lines[1].ends_with(": second"), "{text}"); + std::fs::remove_dir_all(&dir).unwrap(); + assert!(!append_line(std::path::Path::new(""), "no folder"), "a path without a folder is refused"); + } + #[test] fn the_system_title_bar_setting_is_read_from_eframes_settings_file() { let path = std::env::temp_dir().join(format!("texturecraft-titlebar-test-{}.ron", std::process::id())); diff --git a/crates/ui-egui/src/i18n/ar.rs b/crates/ui-egui/src/i18n/ar.rs index b62b6baf..04e2cdee 100644 --- a/crates/ui-egui/src/i18n/ar.rs +++ b/crates/ui-egui/src/i18n/ar.rs @@ -234,6 +234,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Depth of field", "عمق الميدان"), ("Depth of field (viewport and Rendering mode)", "عمق الميدان (منفذ العرض ونمط التصيير)"), ("Depth of the sharp plane along the view (0: the orbit center)", "عمق المستوى الحاد على طول خط النظر (0: مركز المدار)"), + ("Details saved to {file}", "حُفظت التفاصيل في {file}"), ("Difference", "الفرق"), ("Dilation + default background color", "تمديد + لون الخلفية الافتراضي"), ("Dilation + transparent", "تمديد + شفاف"), @@ -789,6 +790,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Texture set channels", "قنوات مجموعة الخامات"), ("Texture set list", "قائمة مجموعات الخامات"), ("Texture sets", "مجموعات الخامات"), + ("TextureCraft had to close:", "اضطر TextureCraft إلى الإغلاق:"), ("TextureCraft PBR - Metallic Roughness", "TextureCraft PBR - خشونة ومعدنية"), ("TextureCraft PBR - Specular Glossiness", "TextureCraft PBR - لمعان وصفاء"), ("TextureCraft project", "مشروع TextureCraft"), diff --git a/crates/ui-egui/src/i18n/de.rs b/crates/ui-egui/src/i18n/de.rs index 45ea5c2c..a10fe322 100644 --- a/crates/ui-egui/src/i18n/de.rs +++ b/crates/ui-egui/src/i18n/de.rs @@ -249,6 +249,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Depth of field", "Schärfentiefe"), ("Depth of field (viewport and Rendering mode)", "Schärfentiefe (Ansichtsfenster und Rendermodus)"), ("Depth of the sharp plane along the view (0: the orbit center)", "Tiefe der Schärfeebene entlang der Blickrichtung (0: Orbit-Mittelpunkt)"), + ("Details saved to {file}", "Details gespeichert in {file}"), ("Difference", "Differenz"), ("Dilation + default background color", "Dilatation + Standard-Hintergrundfarbe"), ("Dilation + transparent", "Dilatation + transparent"), @@ -831,6 +832,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Texture set channels", "Texturset-Kanäle"), ("Texture set list", "Texturset-Liste"), ("Texture sets", "Textursets"), + ("TextureCraft had to close:", "TextureCraft musste beendet werden:"), ("TextureCraft PBR - Metallic Roughness", "TextureCraft PBR - Metallisch/Rauheit"), ("TextureCraft PBR - Specular Glossiness", "TextureCraft PBR - Specular/Glanz"), ("TextureCraft project", "TextureCraft-Projekt"), diff --git a/crates/ui-egui/src/i18n/es.rs b/crates/ui-egui/src/i18n/es.rs index f5040e63..b760a8e7 100644 --- a/crates/ui-egui/src/i18n/es.rs +++ b/crates/ui-egui/src/i18n/es.rs @@ -246,6 +246,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Depth of field", "Profundidad de campo"), ("Depth of field (viewport and Rendering mode)", "Profundidad de campo (ventana gráfica y modo Renderizado)"), ("Depth of the sharp plane along the view (0: the orbit center)", "Profundidad del plano nítido a lo largo de la vista (0: el centro de órbita)"), + ("Details saved to {file}", "Detalles guardados en {file}"), ("Difference", "Diferencia"), ("Dilation + default background color", "Dilatación + color de fondo predeterminado"), ("Dilation + transparent", "Dilatación + transparente"), @@ -819,6 +820,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Texture set channels", "Canales del conjunto de texturas"), ("Texture set list", "Lista de conjuntos de texturas"), ("Texture sets", "Conjuntos de texturas"), + ("TextureCraft had to close:", "TextureCraft tuvo que cerrarse:"), ("TextureCraft PBR - Metallic Roughness", "TextureCraft PBR - Metálico Rugosidad"), ("TextureCraft PBR - Specular Glossiness", "TextureCraft PBR - Especular Brillo"), ("TextureCraft project", "Proyecto de TextureCraft"), diff --git a/crates/ui-egui/src/i18n/fr.rs b/crates/ui-egui/src/i18n/fr.rs index 5a76af66..1f1777f9 100644 --- a/crates/ui-egui/src/i18n/fr.rs +++ b/crates/ui-egui/src/i18n/fr.rs @@ -252,6 +252,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Depth of field", "Profondeur de champ"), ("Depth of field (viewport and Rendering mode)", "Profondeur de champ (fenêtre d'affichage et mode Rendu)"), ("Depth of the sharp plane along the view (0: the orbit center)", "Profondeur du plan net le long de la vue (0 : le centre d'orbite)"), + ("Details saved to {file}", "Détails enregistrés dans {file}"), ("Difference", "Différence"), ("Dilation + default background color", "Dilatation + couleur de fond par défaut"), ("Dilation + transparent", "Dilatation + transparent"), @@ -837,6 +838,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Texture set channels", "Canaux de l'ensemble de textures"), ("Texture set list", "Liste des ensembles de textures"), ("Texture sets", "Ensembles de textures"), + ("TextureCraft had to close:", "TextureCraft a dû se fermer :"), ("TextureCraft PBR - Metallic Roughness", "TextureCraft PBR - Métallique Rugosité"), ("TextureCraft PBR - Specular Glossiness", "TextureCraft PBR - Spéculaire Brillance"), ("TextureCraft project", "Projet TextureCraft"), diff --git a/crates/ui-egui/src/i18n/it.rs b/crates/ui-egui/src/i18n/it.rs index 011fbe11..e4108d6a 100644 --- a/crates/ui-egui/src/i18n/it.rs +++ b/crates/ui-egui/src/i18n/it.rs @@ -252,6 +252,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Depth of field", "Profondità di campo"), ("Depth of field (viewport and Rendering mode)", "Profondità di campo (viewport e modalità Rendering)"), ("Depth of the sharp plane along the view (0: the orbit center)", "Profondità del piano a fuoco lungo la vista (0: il centro di orbita)"), + ("Details saved to {file}", "Dettagli salvati in {file}"), ("Difference", "Differenza"), ("Dilation + default background color", "Dilatazione + colore di sfondo predefinito"), ("Dilation + transparent", "Dilatazione + trasparente"), @@ -828,6 +829,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Texture set channels", "Canali del set di texture"), ("Texture set list", "Elenco set di texture"), ("Texture sets", "Set di texture"), + ("TextureCraft had to close:", "TextureCraft ha dovuto chiudersi:"), ("TextureCraft PBR - Metallic Roughness", "TextureCraft PBR - Metallico Rugosità"), ("TextureCraft PBR - Specular Glossiness", "TextureCraft PBR - Speculare Lucentezza"), ("TextureCraft project", "Progetto TextureCraft"), diff --git a/crates/ui-egui/src/i18n/ja.rs b/crates/ui-egui/src/i18n/ja.rs index bf4e8402..a55f66fa 100644 --- a/crates/ui-egui/src/i18n/ja.rs +++ b/crates/ui-egui/src/i18n/ja.rs @@ -249,6 +249,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Depth of field", "被写界深度"), ("Depth of field (viewport and Rendering mode)", "被写界深度 (ビューポートとレンダリングモード)"), ("Depth of the sharp plane along the view (0: the orbit center)", "ピントが合う面の視線方向の深度 (0: オービット中心)"), + ("Details saved to {file}", "詳細の保存先: {file}"), ("Difference", "差の絶対値"), ("Dilation + default background color", "ダイレーション + デフォルト背景色"), ("Dilation + transparent", "ダイレーション + 透明"), @@ -810,6 +811,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Texture set channels", "テクスチャセットのチャンネル"), ("Texture set list", "テクスチャセット一覧"), ("Texture sets", "テクスチャセット"), + ("TextureCraft had to close:", "TextureCraft を終了する必要がありました:"), ("TextureCraft PBR - Metallic Roughness", "TextureCraft PBR - メタリック/ラフネス"), ("TextureCraft PBR - Specular Glossiness", "TextureCraft PBR - スペキュラー/グロッシネス"), ("TextureCraft project", "TextureCraftプロジェクト"), diff --git a/crates/ui-egui/src/i18n/ko.rs b/crates/ui-egui/src/i18n/ko.rs index a9da933b..eeb97fd9 100644 --- a/crates/ui-egui/src/i18n/ko.rs +++ b/crates/ui-egui/src/i18n/ko.rs @@ -243,6 +243,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Depth of field", "피사계 심도"), ("Depth of field (viewport and Rendering mode)", "피사계 심도 (뷰포트 및 렌더링 모드)"), ("Depth of the sharp plane along the view (0: the orbit center)", "뷰 방향으로 초점 평면의 깊이 (0: 궤도 중심)"), + ("Details saved to {file}", "자세한 내용 저장 위치: {file}"), ("Difference", "차이"), ("Dilation + default background color", "확장 + 기본 배경색"), ("Dilation + transparent", "확장 + 투명"), @@ -801,6 +802,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Texture set channels", "텍스처 세트 채널"), ("Texture set list", "텍스처 세트 목록"), ("Texture sets", "텍스처 세트"), + ("TextureCraft had to close:", "TextureCraft를 종료해야 했습니다:"), ("TextureCraft PBR - Metallic Roughness", "TextureCraft PBR - 메탈릭 러프니스"), ("TextureCraft PBR - Specular Glossiness", "TextureCraft PBR - 스페큘러 글로시니스"), ("TextureCraft project", "TextureCraft 프로젝트"), diff --git a/crates/ui-egui/src/i18n/pt_br.rs b/crates/ui-egui/src/i18n/pt_br.rs index 2da863ef..a0a4f12f 100644 --- a/crates/ui-egui/src/i18n/pt_br.rs +++ b/crates/ui-egui/src/i18n/pt_br.rs @@ -246,6 +246,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Depth of field", "Profundidade de campo"), ("Depth of field (viewport and Rendering mode)", "Profundidade de campo (viewport e modo Renderização)"), ("Depth of the sharp plane along the view (0: the orbit center)", "Profundidade do plano nítido ao longo da vista (0: o centro de órbita)"), + ("Details saved to {file}", "Detalhes salvos em {file}"), ("Difference", "Diferença"), ("Dilation + default background color", "Dilatação + cor de fundo padrão"), ("Dilation + transparent", "Dilatação + transparente"), @@ -816,6 +817,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Texture set channels", "Canais do conjunto de texturas"), ("Texture set list", "Lista de conjuntos de texturas"), ("Texture sets", "Conjuntos de texturas"), + ("TextureCraft had to close:", "O TextureCraft precisou ser fechado:"), ("TextureCraft PBR - Metallic Roughness", "TextureCraft PBR - Metálico Rugosidade"), ("TextureCraft PBR - Specular Glossiness", "TextureCraft PBR - Especular Brilho"), ("TextureCraft project", "Projeto TextureCraft"), diff --git a/crates/ui-egui/src/i18n/zh_hans.rs b/crates/ui-egui/src/i18n/zh_hans.rs index 4727b3e9..743f8cbe 100644 --- a/crates/ui-egui/src/i18n/zh_hans.rs +++ b/crates/ui-egui/src/i18n/zh_hans.rs @@ -216,6 +216,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Depth of field", "景深"), ("Depth of field (viewport and Rendering mode)", "景深(视口和渲染模式)"), ("Depth of the sharp plane along the view (0: the orbit center)", "清晰平面沿视线方向的深度(0:轨道中心)"), + ("Details saved to {file}", "详细信息已保存到 {file}"), ("Difference", "差值"), ("Dilation + default background color", "扩张 + 默认背景色"), ("Dilation + transparent", "扩张 + 透明"), @@ -744,6 +745,7 @@ pub const TABLE: &[(&str, &str)] = &[ ("Texture set channels", "纹理集通道"), ("Texture set list", "纹理集列表"), ("Texture sets", "纹理集"), + ("TextureCraft had to close:", "TextureCraft 不得不关闭:"), ("TextureCraft PBR - Metallic Roughness", "TextureCraft PBR - 金属度/粗糙度"), ("TextureCraft PBR - Specular Glossiness", "TextureCraft PBR - 高光/光泽度"), ("TextureCraft project", "TextureCraft 项目"),