From 102405e0822194c03d49e3c3dc747143f711c6a4 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 19 Feb 2017 12:56:56 +0000 Subject: [PATCH] Fix recursive faults in Window crash logger due to message box event loop. --- src/openttd.h | 14 ++++++++++++++ src/os/windows/crashlog_win.cpp | 3 +++ src/os/windows/win32.cpp | 3 +++ src/window.cpp | 8 ++++++++ 4 files changed, 28 insertions(+) diff --git a/src/openttd.h b/src/openttd.h index 5e360d6fcd..049c849f38 100644 --- a/src/openttd.h +++ b/src/openttd.h @@ -53,6 +53,20 @@ extern GameMode _game_mode; extern SwitchMode _switch_mode; extern bool _exit_game; +#if defined(WIN32) +extern bool _in_event_loop_post_crash; + +inline bool InEventLoopPostCrash() +{ + return _in_event_loop_post_crash; +} +#else +inline bool InEventLoopPostCrash() +{ + return false; +} +#endif + /** Modes of pausing we've got */ enum PauseMode { PM_UNPAUSED = 0, ///< A normal unpaused game diff --git a/src/os/windows/crashlog_win.cpp b/src/os/windows/crashlog_win.cpp index 288619dcab..9c77c878db 100644 --- a/src/os/windows/crashlog_win.cpp +++ b/src/os/windows/crashlog_win.cpp @@ -21,6 +21,7 @@ #include "../../gamelog.h" #include "../../saveload/saveload.h" #include "../../video/video_driver.hpp" +#include "../../openttd.h" #if defined(WITH_DEMANGLE) #include #endif @@ -532,6 +533,8 @@ void *_safe_esp = NULL; static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) { + _in_event_loop_post_crash = true; + if (CrashLogWindows::current != NULL) { CrashLog::AfterCrashLogCleanup(); ExitProcess(2); diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index 344d243143..bf82f6f1f8 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -34,6 +34,8 @@ #undef strncat #undef strncpy +bool _in_event_loop_post_crash; + static bool _has_console; static bool _cursor_disable = true; static bool _cursor_visible = true; @@ -82,6 +84,7 @@ bool LoadLibraryList(Function proc[], const char *dll) void ShowOSErrorBox(const char *buf, bool system) { + _in_event_loop_post_crash = true; MyShowCursor(true); MessageBox(GetActiveWindow(), OTTD2FS(buf), _T("Error!"), MB_ICONSTOP); } diff --git a/src/window.cpp b/src/window.cpp index 24683d0a6a..4d7c452616 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -2579,6 +2579,8 @@ EventState Window::HandleEditBoxKey(int wid, WChar key, uint16 keycode) */ void HandleKeypress(uint keycode, WChar key) { + if (InEventLoopPostCrash()) return; + /* World generation is multithreaded and messes with companies. * But there is no company related window open anyway, so _current_company is not used. */ assert(HasModalProgress() || IsLocalCompany()); @@ -2783,6 +2785,8 @@ static void HandleKeyScrolling() static void MouseLoop(MouseClick click, int mousewheel) { + if (InEventLoopPostCrash()) return; + /* World generation is multithreaded and messes with companies. * But there is no company related window open anyway, so _current_company is not used. */ assert(HasModalProgress() || IsLocalCompany()); @@ -2872,6 +2876,8 @@ static void MouseLoop(MouseClick click, int mousewheel) */ void HandleMouseEvents() { + if (InEventLoopPostCrash()) return; + /* World generation is multithreaded and messes with companies. * But there is no company related window open anyway, so _current_company is not used. */ assert(HasModalProgress() || IsLocalCompany()); @@ -2979,6 +2985,8 @@ static void CheckSoftLimit() */ void InputLoop() { + if (InEventLoopPostCrash()) return; + /* World generation is multithreaded and messes with companies. * But there is no company related window open anyway, so _current_company is not used. */ assert(HasModalProgress() || IsLocalCompany());