diff options
author | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2019-12-19 16:36:49 +0100 |
---|---|---|
committer | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2019-12-19 16:51:32 +0100 |
commit | 98dc07f25fbbea480c99d34472872943b1902ba8 (patch) | |
tree | 0c14fe531d2f91b4680e384c78845983a7872701 /modules/mono/mono_gd | |
parent | 981c6aa102ba50d314a023a96d7affb7081334e5 (diff) |
Mono/C#: Fix Variant -> MonoString* when type is Variant:NIL
`Variant::operator String()` returns "Null" if the type is `Variant:NIL`.
We must consider that and return a null `MonoString*` instead when marshalling.
This was also causing a "Null" error to be displayed when exporting a game
because null string members would be set to "Null" during hot-reload.
Diffstat (limited to 'modules/mono/mono_gd')
-rw-r--r-- | modules/mono/mono_gd/gd_mono_field.cpp | 10 | ||||
-rw-r--r-- | modules/mono/mono_gd/gd_mono_marshal.cpp | 2 |
2 files changed, 10 insertions, 2 deletions
diff --git a/modules/mono/mono_gd/gd_mono_field.cpp b/modules/mono/mono_gd/gd_mono_field.cpp index d84359b1ab..56a9bf46a3 100644 --- a/modules/mono/mono_gd/gd_mono_field.cpp +++ b/modules/mono/mono_gd/gd_mono_field.cpp @@ -110,8 +110,14 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_ } break; case MONO_TYPE_STRING: { - MonoString *mono_string = GDMonoMarshal::mono_string_from_godot(p_value); - mono_field_set_value(p_object, mono_field, mono_string); + if (p_value.get_type() == Variant::NIL) { + // Otherwise, Variant -> String would return the string "Null" + MonoString *mono_string = NULL; + mono_field_set_value(p_object, mono_field, mono_string); + } else { + MonoString *mono_string = GDMonoMarshal::mono_string_from_godot(p_value); + mono_field_set_value(p_object, mono_field, mono_string); + } } break; case MONO_TYPE_VALUETYPE: { diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp index f74fe5715c..9f55b31edc 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.cpp +++ b/modules/mono/mono_gd/gd_mono_marshal.cpp @@ -374,6 +374,8 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty } case MONO_TYPE_STRING: { + if (p_var->get_type() == Variant::NIL) + return NULL; // Otherwise, Variant -> String would return the string "Null" return (MonoObject *)mono_string_from_godot(p_var->operator String()); } break; |