diff options
Diffstat (limited to 'modules/mono/mono_gd')
-rw-r--r-- | modules/mono/mono_gd/gd_mono.cpp | 12 | ||||
-rw-r--r-- | modules/mono/mono_gd/gd_mono_method.cpp | 41 |
2 files changed, 50 insertions, 3 deletions
diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp index d7aedbbcf0..4b5f5eb137 100644 --- a/modules/mono/mono_gd/gd_mono.cpp +++ b/modules/mono/mono_gd/gd_mono.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "gd_mono.h" +#include <mono/metadata/exception.h> #include <mono/metadata/mono-config.h> #include <mono/metadata/mono-debug.h> #include <mono/metadata/mono-gc.h> @@ -47,6 +48,15 @@ #include "../editor/godotsharp_editor.h" #endif +void gdmono_unhandled_exception_hook(MonoObject *exc, void *user_data) { + + (void)user_data; // UNUSED + + ERR_PRINT(GDMonoUtils::get_exception_name_and_message(exc).utf8()); + mono_print_unhandled_exception(exc); + abort(); +} + #ifdef MONO_PRINT_HANDLER_ENABLED void gdmono_MonoPrintCallback(const char *string, mono_bool is_stdout) { @@ -214,6 +224,8 @@ void GDMono::initialize() { // The following assemblies are not required at initialization _load_all_script_assemblies(); + mono_install_unhandled_exception_hook(gdmono_unhandled_exception_hook, NULL); + OS::get_singleton()->print("Mono: ALL IS GOOD\n"); } diff --git a/modules/mono/mono_gd/gd_mono_method.cpp b/modules/mono/mono_gd/gd_mono_method.cpp index 6468e0d3d9..eb97d62900 100644 --- a/modules/mono/mono_gd/gd_mono_method.cpp +++ b/modules/mono/mono_gd/gd_mono_method.cpp @@ -83,9 +83,32 @@ MonoObject *GDMonoMethod::invoke(MonoObject *p_object, const Variant **p_params, mono_array_set(params, MonoObject *, i, boxed_param); } - return mono_runtime_invoke_array(mono_method, p_object, params, r_exc); + MonoObject *exc = NULL; + MonoObject *ret = mono_runtime_invoke_array(mono_method, p_object, params, &exc); + + if (exc) { + if (r_exc) { + *r_exc = exc; + } else { + ERR_PRINT(GDMonoUtils::get_exception_name_and_message(exc).utf8()); + mono_print_unhandled_exception(exc); + } + } + + return ret; } else { - mono_runtime_invoke(mono_method, p_object, NULL, r_exc); + MonoObject *exc = NULL; + mono_runtime_invoke(mono_method, p_object, NULL, &exc); + + if (exc) { + if (r_exc) { + *r_exc = exc; + } else { + ERR_PRINT(GDMonoUtils::get_exception_name_and_message(exc).utf8()); + mono_print_unhandled_exception(exc); + } + } + return NULL; } } @@ -96,7 +119,19 @@ MonoObject *GDMonoMethod::invoke(MonoObject *p_object, MonoObject **r_exc) { } MonoObject *GDMonoMethod::invoke_raw(MonoObject *p_object, void **p_params, MonoObject **r_exc) { - return mono_runtime_invoke(mono_method, p_object, p_params, r_exc); + MonoObject *exc = NULL; + MonoObject *ret = mono_runtime_invoke(mono_method, p_object, p_params, &exc); + + if (exc) { + if (r_exc) { + *r_exc = exc; + } else { + ERR_PRINT(GDMonoUtils::get_exception_name_and_message(exc).utf8()); + mono_print_unhandled_exception(exc); + } + } + + return ret; } bool GDMonoMethod::has_attribute(GDMonoClass *p_attr_class) { |