summaryrefslogtreecommitdiff
path: root/modules/mono/csharp_script.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mono/csharp_script.cpp')
-rw-r--r--modules/mono/csharp_script.cpp87
1 files changed, 64 insertions, 23 deletions
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp
index 5301ea72b4..b475782729 100644
--- a/modules/mono/csharp_script.cpp
+++ b/modules/mono/csharp_script.cpp
@@ -654,6 +654,13 @@ void *CSharpLanguage::alloc_instance_binding_data(Object *p_object) {
StringName type_name = p_object->get_class_name();
+ // ¯\_(ツ)_/¯
+ const ClassDB::ClassInfo *classinfo = ClassDB::classes.getptr(type_name);
+ while (classinfo && !classinfo->exposed)
+ classinfo = classinfo->inherits_ptr;
+ ERR_FAIL_NULL_V(classinfo, NULL);
+ type_name = classinfo->name;
+
GDMonoClass *type_class = GDMonoUtils::type_get_proxy_class(type_name);
ERR_FAIL_NULL_V(type_class, NULL);
@@ -782,7 +789,7 @@ bool CSharpInstance::set(const StringName &p_name, const Variant &p_value) {
if (method) {
MonoObject *ret = method->invoke(mono_object, args);
- if (ret && UNBOX_BOOLEAN(ret))
+ if (ret && GDMonoMarshal::unbox<MonoBoolean>(ret) == true)
return true;
}
@@ -1201,8 +1208,6 @@ bool CSharpScript::_update_exports() {
exported_members_cache.clear();
exported_members_defval_cache.clear();
- const Vector<GDMonoField *> &fields = script_class->get_all_fields();
-
// We are creating a temporary new instance of the class here to get the default value
// TODO Workaround. Should be replaced with IL opcodes analysis
@@ -1226,36 +1231,47 @@ bool CSharpScript::_update_exports() {
return false;
}
- for (int i = 0; i < fields.size(); i++) {
- GDMonoField *field = fields[i];
+ GDMonoClass *top = script_class;
- if (field->is_static() || field->get_visibility() != GDMono::PUBLIC)
- continue;
+ while (top && top != native) {
+ const Vector<GDMonoField *> &fields = top->get_all_fields();
+
+ for (int i = 0; i < fields.size(); i++) {
+ GDMonoField *field = fields[i];
+
+ if (field->is_static() || field->get_visibility() != GDMono::PUBLIC)
+ continue;
- String name = field->get_name();
- StringName cname = name;
+ String name = field->get_name();
+ StringName cname = name;
- Variant::Type type = GDMonoMarshal::managed_to_variant_type(field->get_type());
+ if (member_info.has(cname))
+ continue;
- if (field->has_attribute(CACHED_CLASS(ExportAttribute))) {
- MonoObject *attr = field->get_attribute(CACHED_CLASS(ExportAttribute));
+ Variant::Type type = GDMonoMarshal::managed_to_variant_type(field->get_type());
- // Field has Export attribute
- int hint = CACHED_FIELD(ExportAttribute, hint)->get_int_value(attr);
- String hint_string = CACHED_FIELD(ExportAttribute, hint_string)->get_string_value(attr);
- int usage = CACHED_FIELD(ExportAttribute, usage)->get_int_value(attr);
+ if (field->has_attribute(CACHED_CLASS(ExportAttribute))) {
+ MonoObject *attr = field->get_attribute(CACHED_CLASS(ExportAttribute));
- PropertyInfo prop_info = PropertyInfo(type, name, PropertyHint(hint), hint_string, PropertyUsageFlags(usage));
+ // Field has Export attribute
+ int hint = CACHED_FIELD(ExportAttribute, hint)->get_int_value(attr);
+ String hint_string = CACHED_FIELD(ExportAttribute, hint_string)->get_string_value(attr);
+ int usage = CACHED_FIELD(ExportAttribute, usage)->get_int_value(attr);
- member_info[cname] = prop_info;
- exported_members_cache.push_back(prop_info);
+ PropertyInfo prop_info = PropertyInfo(type, name, PropertyHint(hint), hint_string, PropertyUsageFlags(usage));
- if (tmp_object) {
- exported_members_defval_cache[cname] = GDMonoMarshal::mono_object_to_variant(field->get_value(tmp_object));
+ member_info[cname] = prop_info;
+ exported_members_cache.push_back(prop_info);
+
+ if (tmp_object) {
+ exported_members_defval_cache[cname] = GDMonoMarshal::mono_object_to_variant(field->get_value(tmp_object));
+ }
+ } else {
+ member_info[cname] = PropertyInfo(type, name, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_SCRIPT_VARIABLE);
}
- } else {
- member_info[cname] = PropertyInfo(type, name, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_SCRIPT_VARIABLE);
}
+
+ top = top->get_parent_class();
}
}
@@ -1795,6 +1811,31 @@ RES ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p
#endif
script->set_path(p_original_path);
+
+#ifndef TOOLS_ENABLED
+
+#ifdef DEBUG_ENABLED
+ // User is responsible for thread attach/detach
+ ERR_EXPLAIN("Thread is not attached");
+ CRASH_COND(mono_domain_get() == NULL);
+#endif
+
+#else
+ if (Engine::get_singleton()->is_editor_hint() && mono_domain_get() == NULL) {
+
+ CRASH_COND(Thread::get_caller_id() == Thread::get_main_id());
+
+ // Thread is not attached, but we will make an exception in this case
+ // 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);
+
+ } else // just reload it normally
+#endif
script->reload();
if (r_error)