Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/mono/csharp_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ bool CSharpInstance::set(const StringName &p_name, const Variant &p_value) {
GDMonoProperty *property = top->get_property(p_name);

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;
}

Expand Down
30 changes: 14 additions & 16 deletions modules/mono/mono_gd/gd_mono_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ GDMonoProperty::GDMonoProperty(MonoProperty *p_mono_property, GDMonoClass *p_own
type.type_class = GDMono::get_singleton()->get_class(param_type_class);
}

param_buffer_size = GDMonoMarshal::variant_get_managed_unboxed_size(type);

attrs_fetched = false;
attributes = nullptr;
}
Expand Down Expand Up @@ -147,24 +149,20 @@ bool GDMonoProperty::has_setter() {
return mono_property_get_set_method(mono_property) != nullptr;
}

void GDMonoProperty::set_value(MonoObject *p_object, MonoObject *p_value, MonoException **r_exc) {
MonoMethod *prop_method = mono_property_get_set_method(mono_property);
void *params[1] = { p_value };
MonoException *exc = nullptr;
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_from_variant(MonoObject *p_object, const Variant &p_value, MonoException **r_exc) {
uint8_t *buffer = (uint8_t *)alloca(param_buffer_size);
unsigned int offset = 0;

void GDMonoProperty::set_value(MonoObject *p_object, void **p_params, MonoException **r_exc) {
MonoException *exc = nullptr;
GDMonoUtils::property_set_value(mono_property, p_object, p_params, &exc);
void *params[1] = {
GDMonoMarshal::variant_to_managed_unboxed(p_value, type, buffer, offset)
};

#ifdef DEBUG_ENABLED
CRASH_COND(offset != param_buffer_size);
#endif

MonoException *exc = nullptr;
GDMonoUtils::property_set_value(mono_property, p_object, params, &exc);
if (exc) {
if (r_exc) {
*r_exc = exc;
Expand Down
5 changes: 3 additions & 2 deletions modules/mono/mono_gd/gd_mono_property.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class GDMonoProperty : public IMonoClassMember {
bool attrs_fetched;
MonoCustomAttrInfo *attributes;

unsigned int param_buffer_size;

public:
virtual GDMonoClass *get_enclosing_class() const final { return owner; }

Expand All @@ -64,8 +66,7 @@ class GDMonoProperty : public IMonoClassMember {

_FORCE_INLINE_ ManagedType get_type() const { return type; }

void set_value(MonoObject *p_object, MonoObject *p_value, MonoException **r_exc = nullptr);
void set_value(MonoObject *p_object, void **p_params, MonoException **r_exc = nullptr);
void set_value_from_variant(MonoObject *p_object, const Variant &p_value, MonoException **r_exc = nullptr);
MonoObject *get_value(MonoObject *p_object, MonoException **r_exc = nullptr);

bool get_bool_value(MonoObject *p_object);
Expand Down