Merge pull request #43992 from vnen/variant-internal-object-set

Fix VariantInternal initialization and setting of object
This commit is contained in:
Rémi Verschelde 2020-11-30 20:22:15 +01:00 committed by GitHub
commit 04bef80b42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 22 deletions

View File

@ -777,18 +777,23 @@ String Variant::get_constructor_argument_name(Variant::Type p_type, int p_constr
return construct_data[p_type][p_constructor].arg_names[p_argument]; return construct_data[p_type][p_constructor].arg_names[p_argument];
} }
void VariantInternal::object_assign(Variant *v, const Variant *o) { void VariantInternal::object_assign(Variant *v, const Object *o) {
if (o->_get_obj().obj && o->_get_obj().id.is_reference()) { if (o) {
Reference *reference = static_cast<Reference *>(o->_get_obj().obj); if (o->is_reference()) {
if (!reference->reference()) { Reference *reference = const_cast<Reference *>(static_cast<const Reference *>(o));
v->_get_obj().obj = nullptr; if (!reference->init_ref()) {
v->_get_obj().id = ObjectID(); v->_get_obj().obj = nullptr;
return; v->_get_obj().id = ObjectID();
return;
}
} }
}
v->_get_obj().obj = const_cast<Object *>(o->_get_obj().obj); v->_get_obj().obj = const_cast<Object *>(o);
v->_get_obj().id = o->_get_obj().id; v->_get_obj().id = o->get_instance_id();
} else {
v->_get_obj().obj = nullptr;
v->_get_obj().id = ObjectID();
}
} }
void Variant::get_constructor_list(Type p_type, List<MethodInfo> *r_list) { void Variant::get_constructor_list(Type p_type, List<MethodInfo> *r_list) {

View File

@ -100,21 +100,14 @@ public:
case Variant::PACKED_COLOR_ARRAY: case Variant::PACKED_COLOR_ARRAY:
init_color_array(v); init_color_array(v);
break; break;
case Variant::OBJECT:
object_assign_null(v);
break;
default: default:
break; break;
} }
} }
_FORCE_INLINE_ static void set_object(Variant *v, Object *obj) {
if (obj) {
v->_get_obj().obj = obj;
v->_get_obj().id = obj->get_instance_id();
} else {
v->_get_obj().obj = nullptr;
v->_get_obj().id = ObjectID();
}
}
// Atomic types. // Atomic types.
_FORCE_INLINE_ static bool *get_bool(Variant *v) { return &v->_data._bool; } _FORCE_INLINE_ static bool *get_bool(Variant *v) { return &v->_data._bool; }
_FORCE_INLINE_ static const bool *get_bool(const Variant *v) { return &v->_data._bool; } _FORCE_INLINE_ static const bool *get_bool(const Variant *v) { return &v->_data._bool; }
@ -285,7 +278,11 @@ public:
v->clear(); v->clear();
} }
static void object_assign(Variant *v, const Variant *o); //needs to use reference, do away static void object_assign(Variant *v, const Object *o); // Needs Reference, so it's implemented elsewhere.
_FORCE_INLINE_ static void object_assign(Variant *v, const Variant *o) {
object_assign(v, o->_get_obj().obj);
}
_FORCE_INLINE_ static void object_assign_null(Variant *v) { _FORCE_INLINE_ static void object_assign_null(Variant *v) {
v->_get_obj().obj = nullptr; v->_get_obj().obj = nullptr;

View File

@ -1653,7 +1653,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
VariantInternal::initialize(ret, Variant::OBJECT); VariantInternal::initialize(ret, Variant::OBJECT);
Object **ret_opaque = VariantInternal::get_object(ret); Object **ret_opaque = VariantInternal::get_object(ret);
method->ptrcall(base_obj, argptrs, ret_opaque); method->ptrcall(base_obj, argptrs, ret_opaque);
VariantInternal::set_object(ret, *ret_opaque); VariantInternal::object_assign(ret, *ret_opaque); // Set so ID is correct too.
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
if (GDScriptLanguage::get_singleton()->profiling) { if (GDScriptLanguage::get_singleton()->profiling) {