diff options
-rw-r--r-- | modules/mono/editor/csharp_project.cpp | 6 | ||||
-rw-r--r-- | modules/mono/mono_gd/gd_mono_field.cpp | 2 | ||||
-rw-r--r-- | modules/mono/mono_gd/gd_mono_marshal.cpp | 5 | ||||
-rw-r--r-- | modules/mono/mono_gd/gd_mono_marshal.h | 9 |
4 files changed, 15 insertions, 7 deletions
diff --git a/modules/mono/editor/csharp_project.cpp b/modules/mono/editor/csharp_project.cpp index 9a1efb4423..d5819a4ca3 100644 --- a/modules/mono/editor/csharp_project.cpp +++ b/modules/mono/editor/csharp_project.cpp @@ -54,7 +54,7 @@ String generate_core_api_project(const String &p_dir, const Vector<String> &p_fi ERR_FAIL_V(String()); } - return ret ? GDMonoMarshal::mono_string_to_godot((MonoString *)ret) : ""; + return ret ? GDMonoMarshal::mono_string_to_godot((MonoString *)ret) : String(); } String generate_editor_api_project(const String &p_dir, const String &p_core_dll_path, const Vector<String> &p_files) { @@ -75,7 +75,7 @@ String generate_editor_api_project(const String &p_dir, const String &p_core_dll ERR_FAIL_V(String()); } - return ret ? GDMonoMarshal::mono_string_to_godot((MonoString *)ret) : ""; + return ret ? GDMonoMarshal::mono_string_to_godot((MonoString *)ret) : String(); } String generate_game_project(const String &p_dir, const String &p_name, const Vector<String> &p_files) { @@ -96,7 +96,7 @@ String generate_game_project(const String &p_dir, const String &p_name, const Ve ERR_FAIL_V(String()); } - return ret ? GDMonoMarshal::mono_string_to_godot((MonoString *)ret) : ""; + return ret ? GDMonoMarshal::mono_string_to_godot((MonoString *)ret) : String(); } void add_item(const String &p_project_path, const String &p_item_type, const String &p_include) { diff --git a/modules/mono/mono_gd/gd_mono_field.cpp b/modules/mono/mono_gd/gd_mono_field.cpp index eb34f9dd3f..63b24f3ee6 100644 --- a/modules/mono/mono_gd/gd_mono_field.cpp +++ b/modules/mono/mono_gd/gd_mono_field.cpp @@ -290,7 +290,7 @@ int GDMonoField::get_int_value(MonoObject *p_object) { String GDMonoField::get_string_value(MonoObject *p_object) { MonoObject *val = get_value(p_object); - return val ? GDMonoMarshal::mono_string_to_godot((MonoString *)val) : String(); + return GDMonoMarshal::mono_string_to_godot((MonoString *)val); } bool GDMonoField::has_attribute(GDMonoClass *p_attr_class) { diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp index 8bc2bb5096..d744d24f24 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.cpp +++ b/modules/mono/mono_gd/gd_mono_marshal.cpp @@ -490,8 +490,9 @@ Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type) { return unbox<double>(p_obj); case MONO_TYPE_STRING: { - String str = mono_string_to_godot((MonoString *)p_obj); - return str; + if (p_obj == NULL) + return Variant(); // NIL + return mono_string_to_godot_not_null((MonoString *)p_obj); } break; case MONO_TYPE_VALUETYPE: { diff --git a/modules/mono/mono_gd/gd_mono_marshal.h b/modules/mono/mono_gd/gd_mono_marshal.h index 443e947fb5..1be4be1a1c 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.h +++ b/modules/mono/mono_gd/gd_mono_marshal.h @@ -62,13 +62,20 @@ Variant::Type managed_to_variant_type(const ManagedType &p_type); String mono_to_utf8_string(MonoString *p_mono_string); String mono_to_utf16_string(MonoString *p_mono_string); -_FORCE_INLINE_ String mono_string_to_godot(MonoString *p_mono_string) { +_FORCE_INLINE_ String mono_string_to_godot_not_null(MonoString *p_mono_string) { if (sizeof(CharType) == 2) return mono_to_utf16_string(p_mono_string); return mono_to_utf8_string(p_mono_string); } +_FORCE_INLINE_ String mono_string_to_godot(MonoString *p_mono_string) { + if (p_mono_string == NULL) + return String(); + + return mono_string_to_godot_not_null(p_mono_string); +} + _FORCE_INLINE_ MonoString *mono_from_utf8_string(const String &p_string) { return mono_string_new(mono_domain_get(), p_string.utf8().get_data()); } |