From c27f44f52505954c4bd49bd3ba069e281ec7929b Mon Sep 17 00:00:00 2001 From: Ibrahn Sahir Date: Thu, 23 May 2019 19:57:10 +0100 Subject: [PATCH] Check project settings live before lookup in crash handler In x11, windows and osx crash handlers, check project settings exists before looking up the crash handler message setting. Avoids crashing the crash handler when handling a crash outside project settings lifetime. Instead omitting the configurable message and continuing with trace dump. (cherry picked from commit 63068e2ccddfebbec14b806af244daa4cb4d65a8) --- platform/osx/crash_handler_osx.mm | 7 ++++++- platform/windows/crash_handler_win.cpp | 9 +++++++-- platform/x11/crash_handler_x11.cpp | 7 ++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/platform/osx/crash_handler_osx.mm b/platform/osx/crash_handler_osx.mm index 46efca6ef88..52a7bbd9225 100644 --- a/platform/osx/crash_handler_osx.mm +++ b/platform/osx/crash_handler_osx.mm @@ -81,7 +81,12 @@ static void handle_crash(int sig) { void *bt_buffer[256]; size_t size = backtrace(bt_buffer, 256); String _execpath = OS::get_singleton()->get_executable_path(); - String msg = GLOBAL_GET("debug/settings/crash_handler/message"); + + String msg; + const ProjectSettings *proj_settings = ProjectSettings::get_singleton(); + if (proj_settings) { + msg = proj_settings->get("debug/settings/crash_handler/message"); + } // Dump the backtrace to stderr with a message to the user fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig); diff --git a/platform/windows/crash_handler_win.cpp b/platform/windows/crash_handler_win.cpp index 04f45701c2c..9825415c27f 100644 --- a/platform/windows/crash_handler_win.cpp +++ b/platform/windows/crash_handler_win.cpp @@ -160,11 +160,16 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) { line.SizeOfStruct = sizeof(line); IMAGE_NT_HEADERS *h = ImageNtHeader(base); DWORD image_type = h->FileHeader.Machine; - int n = 0; - String msg = GLOBAL_GET("debug/settings/crash_handler/message"); + + String msg; + const ProjectSettings *proj_settings = ProjectSettings::get_singleton(); + if (proj_settings) { + msg = proj_settings->get("debug/settings/crash_handler/message"); + } fprintf(stderr, "Dumping the backtrace. %ls\n", msg.c_str()); + int n = 0; do { if (skip_first) { skip_first = false; diff --git a/platform/x11/crash_handler_x11.cpp b/platform/x11/crash_handler_x11.cpp index 9680f744a4b..3de3bda236c 100644 --- a/platform/x11/crash_handler_x11.cpp +++ b/platform/x11/crash_handler_x11.cpp @@ -52,7 +52,12 @@ static void handle_crash(int sig) { void *bt_buffer[256]; size_t size = backtrace(bt_buffer, 256); String _execpath = OS::get_singleton()->get_executable_path(); - String msg = GLOBAL_GET("debug/settings/crash_handler/message"); + + String msg; + const ProjectSettings *proj_settings = ProjectSettings::get_singleton(); + if (proj_settings) { + msg = proj_settings->get("debug/settings/crash_handler/message"); + } // Dump the backtrace to stderr with a message to the user fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig);