diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-10-23 07:40:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-23 07:40:32 +0200 |
commit | 346326528baaf76d9fc85f996cdd4316ab999133 (patch) | |
tree | 7a06a87dea1382923ef147799c3d68c3d3156fbf /modules/mono/mono_gd | |
parent | 489d1b7eb3af914efd43a9217a59a7a84024f407 (diff) | |
parent | 45e5e23ee83d202461f1753b1d94afc51d3a5aa1 (diff) |
Merge pull request #12333 from neikeq/ñ
Mono: Prevent raising exceptions in native code
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) { |