2017-10-02 23:24:00 +02:00
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
/* gd_mono_internals.cpp */
|
2017-10-02 23:24:00 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2021-09-12 20:21:15 +02:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-10-02 23:24:00 +02:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
#include "gd_mono_internals.h"
|
|
|
|
|
|
|
|
#include "../csharp_script.h"
|
2018-06-26 21:03:42 +02:00
|
|
|
#include "../utils/macros.h"
|
2017-10-02 23:24:00 +02:00
|
|
|
#include "gd_mono_utils.h"
|
|
|
|
|
2020-02-27 03:30:20 +01:00
|
|
|
#include "core/debugger/engine_debugger.h"
|
|
|
|
#include "core/debugger/script_debugger.h"
|
|
|
|
|
2018-06-26 21:03:42 +02:00
|
|
|
#include <mono/metadata/exception.h>
|
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
namespace GDMonoInternals {
|
2018-06-26 21:03:42 +02:00
|
|
|
void unhandled_exception(MonoException *p_exc) {
|
2020-06-25 23:28:51 +02:00
|
|
|
mono_print_unhandled_exception((MonoObject *)p_exc);
|
2021-02-18 16:18:33 +01:00
|
|
|
gd_unhandled_exception_event(p_exc);
|
2019-07-24 23:13:24 +02:00
|
|
|
|
|
|
|
if (GDMono::get_singleton()->get_unhandled_exception_policy() == GDMono::POLICY_TERMINATE_APP) {
|
|
|
|
// Too bad 'mono_invoke_unhandled_exception_hook' is not exposed to embedders
|
2021-02-18 16:18:33 +01:00
|
|
|
mono_unhandled_exception((MonoObject *)p_exc);
|
2020-04-02 01:20:12 +02:00
|
|
|
GDMono::unhandled_exception_hook((MonoObject *)p_exc, nullptr);
|
2019-07-24 23:13:24 +02:00
|
|
|
GD_UNREACHABLE();
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG_ENABLED
|
2020-07-05 19:19:36 +02:00
|
|
|
GDMonoUtils::debug_send_unhandled_exception_error(p_exc);
|
|
|
|
if (EngineDebugger::is_active()) {
|
2020-02-27 03:30:20 +01:00
|
|
|
EngineDebugger::get_singleton()->poll_events(false);
|
2020-07-05 19:19:36 +02:00
|
|
|
}
|
2019-07-24 23:13:24 +02:00
|
|
|
#endif
|
|
|
|
}
|
2018-06-26 21:03:42 +02:00
|
|
|
}
|
2021-02-18 16:18:33 +01:00
|
|
|
|
|
|
|
void gd_unhandled_exception_event(MonoException *p_exc) {
|
|
|
|
MonoImage *mono_image = GDMono::get_singleton()->get_core_api_assembly()->get_image();
|
|
|
|
|
|
|
|
MonoClass *gd_klass = mono_class_from_name(mono_image, "Godot", "GD");
|
2021-09-12 20:21:15 +02:00
|
|
|
MonoMethod *unhandled_exception_method = mono_class_get_method_from_name(gd_klass, "OnUnhandledException", 1);
|
2021-02-18 16:18:33 +01:00
|
|
|
void *args[1];
|
|
|
|
args[0] = p_exc;
|
|
|
|
mono_runtime_invoke(unhandled_exception_method, nullptr, (void **)args, nullptr);
|
|
|
|
}
|
2017-12-06 21:36:34 +01:00
|
|
|
} // namespace GDMonoInternals
|