1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-08 12:40:44 +00:00

C#: Fix property set call boxing value when unboxed was expected

This commit is contained in:
Ignacio Roldán Etcheverry
2021-10-19 00:26:56 +02:00
committed by Raul Santos
parent b775573a21
commit e282ee0a48
3 changed files with 18 additions and 19 deletions

View File

@@ -1465,7 +1465,7 @@ bool CSharpInstance::set(const StringName &p_name, const Variant &p_value) {
GDMonoProperty *property = top->get_property(p_name); GDMonoProperty *property = top->get_property(p_name);
if (property) { if (property) {
property->set_value(mono_object, GDMonoMarshal::variant_to_mono_object(p_value, property->get_type())); property->set_value_from_variant(mono_object, p_value);
return true; return true;
} }

View File

@@ -65,6 +65,8 @@ GDMonoProperty::GDMonoProperty(MonoProperty *p_mono_property, GDMonoClass *p_own
type.type_class = GDMono::get_singleton()->get_class(param_type_class); type.type_class = GDMono::get_singleton()->get_class(param_type_class);
} }
param_buffer_size = GDMonoMarshal::variant_get_managed_unboxed_size(type);
attrs_fetched = false; attrs_fetched = false;
attributes = NULL; attributes = NULL;
} }
@@ -141,24 +143,20 @@ bool GDMonoProperty::has_setter() {
return mono_property_get_set_method(mono_property) != NULL; return mono_property_get_set_method(mono_property) != NULL;
} }
void GDMonoProperty::set_value(MonoObject *p_object, MonoObject *p_value, MonoException **r_exc) { void GDMonoProperty::set_value_from_variant(MonoObject *p_object, const Variant &p_value, MonoException **r_exc) {
MonoMethod *prop_method = mono_property_get_set_method(mono_property); uint8_t *buffer = (uint8_t *)alloca(param_buffer_size);
void *params[1] = { p_value }; unsigned int offset = 0;
MonoException *exc = NULL;
GDMonoUtils::runtime_invoke(prop_method, p_object, params, &exc);
if (exc) {
if (r_exc) {
*r_exc = exc;
} else {
GDMonoUtils::set_pending_exception(exc);
}
}
}
void GDMonoProperty::set_value(MonoObject *p_object, void **p_params, MonoException **r_exc) { void *params[1] = {
MonoException *exc = NULL; GDMonoMarshal::variant_to_managed_unboxed(p_value, type, buffer, offset)
GDMonoUtils::property_set_value(mono_property, p_object, p_params, &exc); };
#ifdef DEBUG_ENABLED
CRASH_COND(offset != param_buffer_size);
#endif
MonoException *exc = NULL;
GDMonoUtils::property_set_value(mono_property, p_object, params, &exc);
if (exc) { if (exc) {
if (r_exc) { if (r_exc) {
*r_exc = exc; *r_exc = exc;

View File

@@ -45,6 +45,8 @@ class GDMonoProperty : public IMonoClassMember {
bool attrs_fetched; bool attrs_fetched;
MonoCustomAttrInfo *attributes; MonoCustomAttrInfo *attributes;
unsigned int param_buffer_size;
public: public:
virtual GDMonoClass *get_enclosing_class() const GD_FINAL { return owner; } virtual GDMonoClass *get_enclosing_class() const GD_FINAL { return owner; }
@@ -64,8 +66,7 @@ public:
_FORCE_INLINE_ ManagedType get_type() const { return type; } _FORCE_INLINE_ ManagedType get_type() const { return type; }
void set_value(MonoObject *p_object, MonoObject *p_value, MonoException **r_exc = NULL); void set_value_from_variant(MonoObject *p_object, const Variant &p_value, MonoException **r_exc = NULL);
void set_value(MonoObject *p_object, void **p_params, MonoException **r_exc = NULL);
MonoObject *get_value(MonoObject *p_object, MonoException **r_exc = NULL); MonoObject *get_value(MonoObject *p_object, MonoException **r_exc = NULL);
bool get_bool_value(MonoObject *p_object); bool get_bool_value(MonoObject *p_object);