From 29a37c2e0bd545f145c14781b4c9853a1e7ef1a1 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sun, 27 Aug 2023 19:58:31 +0200 Subject: [PATCH] Change: [Win32] unify the crashlog handler with the other OSes (#11236) While at it, make the crash text a bit more readable, and sync this with MacOS. --- src/os/macosx/crashlog_osx.cpp | 7 ++++--- src/os/windows/crashlog_win.cpp | 33 +++++---------------------------- src/os/windows/ottdres.rc.in | 1 - 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/src/os/macosx/crashlog_osx.cpp b/src/os/macosx/crashlog_osx.cpp index 72ebff316c..e9f8e156f1 100644 --- a/src/os/macosx/crashlog_osx.cpp +++ b/src/os/macosx/crashlog_osx.cpp @@ -174,9 +174,10 @@ public: "A serious fault condition occurred in the game. The game will shut down."; std::string message = fmt::format( - "Please send the generated crash information and the last (auto)save to the developers. " - "This will greatly help debugging. The correct place to do this is https://github.com/OpenTTD/OpenTTD/issues.\n\n" - "Generated file(s):\n{}\n{}\n{}\n{}", + "Please send crash.log, crash.dmp, and crash.sav to the developers. " + "This will greatly help debugging.\n\n" + "https://github.com/OpenTTD/OpenTTD/issues.\n\n" + "{}\n{}\n{}\n{}", this->crashlog_filename, this->crashdump_filename, this->savegame_filename, this->screenshot_filename); ShowMacDialog(crash_title, message.c_str(), "Quit"); diff --git a/src/os/windows/crashlog_win.cpp b/src/os/windows/crashlog_win.cpp index 520c17f25d..31f703cfbe 100644 --- a/src/os/windows/crashlog_win.cpp +++ b/src/os/windows/crashlog_win.cpp @@ -270,12 +270,7 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) CrashLogWindows *log = new CrashLogWindows(ep); CrashLogWindows::current = log; - auto output_iterator = std::back_inserter(log->crashlog); - log->FillCrashLog(output_iterator); - log->WriteCrashDump(); - log->WriteCrashLog(); - log->WriteScreenshot(); - log->SendSurvey(); + log->MakeCrashLog(); /* Close any possible log files */ CloseConsoleLogIfActive(); @@ -350,17 +345,11 @@ static bool _expanded; static const wchar_t _crash_desc[] = L"A serious fault condition occurred in the game. The game will shut down.\n" - L"Please send the crash information and the crash.dmp file (if any) to the developers.\n" - L"This will greatly help debugging. The correct place to do this is https://github.com/OpenTTD/OpenTTD/issues. " - L"The information contained in the report is displayed below.\n" - L"Press \"Emergency save\" to attempt saving the game. Generated file(s):\n" + L"Please send crash.log, crash.dmp, and crash.sav to the developers.\n" + L"This will greatly help debugging.\n\n" + L"https://github.com/OpenTTD/OpenTTD/issues\n\n" L"%s"; -static const wchar_t _save_succeeded[] = - L"Emergency save succeeded.\nIts location is '%s'.\n" - L"Be aware that critical parts of the internal game state may have become " - L"corrupted. The saved game is not guaranteed to work."; - static const wchar_t * const _expand_texts[] = {L"S&how report >>", L"&Hide report <<" }; static void SetWndSize(HWND wnd, int mode) @@ -403,7 +392,7 @@ static INT_PTR CALLBACK CrashDialogFunc(HWND wnd, UINT msg, WPARAM wParam, LPARA } *p = '\0'; - /* Add path to crash.log and crash.dmp (if any) to the crash window text */ + /* Add path to all files to the crash window text */ size_t len = wcslen(_crash_desc) + 2; len += wcslen(convert_to_fs(CrashLogWindows::current->crashlog_filename, filenamebuf, lengthof(filenamebuf))) + 2; len += wcslen(convert_to_fs(CrashLogWindows::current->crashdump_filename, filenamebuf, lengthof(filenamebuf))) + 2; @@ -434,18 +423,6 @@ static INT_PTR CALLBACK CrashDialogFunc(HWND wnd, UINT msg, WPARAM wParam, LPARA case 12: // Close CrashLog::AfterCrashLogCleanup(); ExitProcess(2); - case 13: // Emergency save - wchar_t filenamebuf[MAX_PATH * 2]; - if (CrashLogWindows::current->WriteSavegame()) { - convert_to_fs(CrashLogWindows::current->savegame_filename, filenamebuf, lengthof(filenamebuf)); - size_t len = lengthof(_save_succeeded) + wcslen(filenamebuf) + 1; - static wchar_t text[lengthof(_save_succeeded) + MAX_PATH * 2 + 1]; - _snwprintf(text, len, _save_succeeded, filenamebuf); - MessageBox(wnd, text, L"Save successful", MB_ICONINFORMATION); - } else { - MessageBox(wnd, L"Save failed", L"Save failed", MB_ICONINFORMATION); - } - break; case 15: // Expand window to show crash-message _expanded = !_expanded; SetWndSize(wnd, _expanded); diff --git a/src/os/windows/ottdres.rc.in b/src/os/windows/ottdres.rc.in index 279389a04c..e09d181ed7 100644 --- a/src/os/windows/ottdres.rc.in +++ b/src/os/windows/ottdres.rc.in @@ -50,7 +50,6 @@ CAPTION "Fatal Application Failure" FONT 8, "MS Sans Serif" BEGIN PUSHBUTTON "&Close",12,7,82,60,14 - PUSHBUTTON "&Emergency save",13,158,82,60,14 PUSHBUTTON "",15,238,82,60,14 EDITTEXT 11,7,103,291,118,ES_MULTILINE | ES_READONLY | WS_VSCROLL | WS_HSCROLL | NOT WS_TABSTOP