diff options
-rw-r--r-- | core/os/main_loop.cpp | 1 | ||||
-rw-r--r-- | core/os/main_loop.h | 1 | ||||
-rw-r--r-- | modules/gdnative/nativescript/nativescript.cpp | 19 | ||||
-rw-r--r-- | modules/gdnative/nativescript/nativescript.h | 3 | ||||
-rw-r--r-- | platform/osx/crash_handler_osx.mm | 4 | ||||
-rw-r--r-- | platform/windows/crash_handler_win.cpp | 3 | ||||
-rw-r--r-- | platform/x11/crash_handler_x11.cpp | 4 | ||||
-rw-r--r-- | scene/main/scene_tree.cpp | 5 |
8 files changed, 40 insertions, 0 deletions
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index 916c86613e..c51801e3e2 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -58,6 +58,7 @@ void MainLoop::_bind_methods() { BIND_CONSTANT(NOTIFICATION_OS_MEMORY_WARNING); BIND_CONSTANT(NOTIFICATION_TRANSLATION_CHANGED); BIND_CONSTANT(NOTIFICATION_WM_ABOUT); + BIND_CONSTANT(NOTIFICATION_CRASH); }; void MainLoop::set_init_script(const Ref<Script> &p_init_script) { diff --git a/core/os/main_loop.h b/core/os/main_loop.h index 546e4e280c..f96e46141e 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -62,6 +62,7 @@ public: // fixes this issue. NOTIFICATION_TRANSLATION_CHANGED = 90, NOTIFICATION_WM_ABOUT = 91, + NOTIFICATION_CRASH = 92, }; virtual void input_event(const Ref<InputEvent> &p_event); diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index d6abbc1bcf..7bab718b81 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -697,11 +697,21 @@ Variant NativeScriptInstance::call(const StringName &p_method, const Variant **p Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method); if (E) { godot_variant result; + +#ifdef DEBUG_ENABLED + current_method_call = p_method; +#endif + result = E->get().method.method((godot_object *)owner, E->get().method.method_data, userdata, p_argcount, (godot_variant **)p_args); + +#ifdef DEBUG_ENABLED + current_method_call = ""; +#endif + Variant res = *(Variant *)&result; godot_variant_destroy(&result); r_error.error = Variant::CallError::CALL_OK; @@ -716,6 +726,15 @@ Variant NativeScriptInstance::call(const StringName &p_method, const Variant **p } void NativeScriptInstance::notification(int p_notification) { +#ifdef DEBUG_ENABLED + if (p_notification == MainLoop::NOTIFICATION_CRASH) { + if (current_method_call != StringName("")) { + ERR_PRINTS("NativeScriptInstance detected crash on method: " + current_method_call); + current_method_call = ""; + } + } +#endif + Variant value = p_notification; const Variant *args[1] = { &value }; call_multilevel("_notification", args, 1); diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h index b47962dc37..be093dde4b 100644 --- a/modules/gdnative/nativescript/nativescript.h +++ b/modules/gdnative/nativescript/nativescript.h @@ -181,6 +181,9 @@ class NativeScriptInstance : public ScriptInstance { Object *owner; Ref<NativeScript> script; +#ifdef DEBUG_ENABLED + StringName current_method_call; +#endif void _ml_call_reversed(NativeScriptDesc *script_data, const StringName &p_method, const Variant **p_args, int p_argcount); diff --git a/platform/osx/crash_handler_osx.mm b/platform/osx/crash_handler_osx.mm index 99ce25adfb..1664c5ce8e 100644 --- a/platform/osx/crash_handler_osx.mm +++ b/platform/osx/crash_handler_osx.mm @@ -78,6 +78,10 @@ static void handle_crash(int sig) { // Dump the backtrace to stderr with a message to the user fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig); + + if (OS::get_singleton()->get_main_loop()) + OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH); + fprintf(stderr, "Dumping the backtrace. %ls\n", msg.c_str()); char **strings = backtrace_symbols(bt_buffer, size); if (strings) { diff --git a/platform/windows/crash_handler_win.cpp b/platform/windows/crash_handler_win.cpp index 804c2d44eb..76a227c608 100644 --- a/platform/windows/crash_handler_win.cpp +++ b/platform/windows/crash_handler_win.cpp @@ -124,6 +124,9 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) { fprintf(stderr, "%s: Program crashed\n", __FUNCTION__); + if (OS::get_singleton()->get_main_loop()) + OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH); + // Load the symbols: if (!SymInitialize(process, NULL, false)) return EXCEPTION_CONTINUE_SEARCH; diff --git a/platform/x11/crash_handler_x11.cpp b/platform/x11/crash_handler_x11.cpp index d39fc33f81..960105271b 100644 --- a/platform/x11/crash_handler_x11.cpp +++ b/platform/x11/crash_handler_x11.cpp @@ -55,6 +55,10 @@ static void handle_crash(int sig) { // Dump the backtrace to stderr with a message to the user fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig); + + if (OS::get_singleton()->get_main_loop()) + OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH); + fprintf(stderr, "Dumping the backtrace. %ls\n", msg.c_str()); char **strings = backtrace_symbols(bt_buffer, size); if (strings) { diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 8d6e57b335..5caba8ef20 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -656,6 +656,11 @@ void SceneTree::_notification(int p_notification) { #endif } break; + case NOTIFICATION_CRASH: { + + get_root()->propagate_notification(p_notification); + } break; + default: break; }; |