From 89e84185e8cbd08531ae33554cf78ffba692cf7a Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Tue, 24 Apr 2018 20:36:17 +0200 Subject: [PATCH 1/3] Mono: Fix crash on script load if the scripts domain isn't loaded --- modules/mono/csharp_script.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 1d0afa7f2d3..25407982063 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -2288,7 +2288,9 @@ RES ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p CRASH_COND(mono_domain_get() == NULL); #endif -#else +#endif + +#ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint() && mono_domain_get() == NULL) { CRASH_COND(Thread::get_caller_id() == Thread::get_main_id()); @@ -2297,14 +2299,20 @@ RES ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p // because this may be called by one of the editor's worker threads. // Attach this thread temporarily to reload the script. - MonoThread *mono_thread = mono_thread_attach(SCRIPTS_DOMAIN); - CRASH_COND(mono_thread == NULL); - script->reload(); - mono_thread_detach(mono_thread); + if (SCRIPTS_DOMAIN) { + MonoThread *mono_thread = mono_thread_attach(SCRIPTS_DOMAIN); + CRASH_COND(mono_thread == NULL); + script->reload(); + mono_thread_detach(mono_thread); + } - } else // just reload it normally + } else { // just reload it normally +#endif + script->reload(); + +#ifdef TOOLS_ENABLED + } #endif - script->reload(); if (r_error) *r_error = OK; From f8ce412560ed3061340f4b0b9e0457a1249fb528 Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Tue, 24 Apr 2018 20:42:31 +0200 Subject: [PATCH 2/3] Mono: Do not spam script class not found error Print this error only when trying to instantiate the script. This way we prevent errors being printed for source files which are not meant to be used as scripts. --- modules/mono/csharp_script.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 25407982063..adc5f16f92c 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -1954,8 +1954,12 @@ Variant CSharpScript::_new(const Variant **p_args, int p_argcount, Variant::Call ScriptInstance *CSharpScript::instance_create(Object *p_this) { - if (!valid) - return NULL; + if (!script_class) { + ERR_EXPLAIN("Cannot find class " + name + " for script " + get_path()); + ERR_FAIL_V(NULL); + } + + ERR_FAIL_COND_V(!valid, NULL); if (!tool && !ScriptServer::is_scripting_enabled()) { #ifdef TOOLS_ENABLED @@ -2045,20 +2049,15 @@ Error CSharpScript::reload(bool p_keep_state) { if (project_assembly) { script_class = project_assembly->get_object_derived_class(name); - if (!script_class) { - ERR_PRINTS("Cannot find class " + name + " for script " + get_path()); - } -#ifdef DEBUG_ENABLED - else if (OS::get_singleton()->is_stdout_verbose()) { - OS::get_singleton()->print(String("Found class " + script_class->get_namespace() + "." + - script_class->get_name() + " for script " + get_path() + "\n") - .utf8()); - } -#endif - valid = script_class != NULL; if (script_class) { +#ifdef DEBUG_ENABLED + OS::get_singleton()->print(String("Found class " + script_class->get_namespace() + "." + + script_class->get_name() + " for script " + get_path() + "\n") + .utf8()); +#endif + tool = script_class->has_attribute(CACHED_CLASS(ToolAttribute)); native = GDMonoUtils::get_class_native_base(script_class); From ff7fe9e771c0146b79aea7fa23a7bf262397992c Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Tue, 24 Apr 2018 20:46:28 +0200 Subject: [PATCH 3/3] Mono: Fix '!t' error messages when generating bindings This error wasn't affecting the bindings generation process. --- modules/mono/editor/bindings_generator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index a210b8e480d..fadcc4ef57b 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -730,7 +730,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str } output.push_back(INDENT1 "public "); - bool is_abstract = !ClassDB::can_instance(itype.name) && ClassDB::is_class_enabled(itype.name); // can_instance returns true if there's a constructor and the class is not 'disabled' + bool is_abstract = itype.is_object_type && !ClassDB::can_instance(itype.name) && ClassDB::is_class_enabled(itype.name); // can_instance returns true if there's a constructor and the class is not 'disabled' output.push_back(itype.is_singleton ? "static class " : (is_abstract ? "abstract class " : "class ")); output.push_back(itype.proxy_name);