Add a new notification to detect crashes on native scripts

This commit is contained in:
Marcelo Fernandez 2018-07-02 16:18:58 -03:00
parent 2dc738ce27
commit deebeb2742
8 changed files with 40 additions and 0 deletions

View file

@ -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);