From a685535ad5ae834617c031e15e5a90cf275cccc7 Mon Sep 17 00:00:00 2001 From: George Marques Date: Thu, 19 Aug 2021 20:19:47 -0300 Subject: [PATCH] Fix initialization of objects in VariantInternal --- core/variant/variant_internal.h | 26 ++++++++++++++++++++++++-- modules/gdscript/gdscript_vm.cpp | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h index 566b14736ee..40c8a1bfde0 100644 --- a/core/variant/variant_internal.h +++ b/core/variant/variant_internal.h @@ -104,7 +104,7 @@ public: init_color_array(v); break; case Variant::OBJECT: - object_assign_null(v); + init_object(v); break; default: break; @@ -280,6 +280,10 @@ public: v->_data.packed_array = Variant::PackedArrayRef::create(Vector()); v->type = Variant::PACKED_COLOR_ARRAY; } + _FORCE_INLINE_ static void init_object(Variant *v) { + object_assign_null(v); + v->type = Variant::OBJECT; + } _FORCE_INLINE_ static void clear(Variant *v) { v->clear(); @@ -1173,7 +1177,7 @@ struct VariantInitializer { template <> struct VariantInitializer { - static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::object_assign_null(v); } + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_object(v); } }; template @@ -1405,4 +1409,22 @@ struct VariantTypeConstructor { } }; +template <> +struct VariantTypeConstructor { + _FORCE_INLINE_ static void variant_from_type(void *p_variant, void *p_value) { + Variant *variant = reinterpret_cast(p_variant); + VariantInitializer::init(variant); + Object *value = *(reinterpret_cast(p_value)); + if (value) { + VariantInternalAccessor::set(variant, value); + VariantInternalAccessor::set(variant, value->get_instance_id()); + } + } + + _FORCE_INLINE_ static void type_from_variant(void *p_value, void *p_variant) { + Object **value = reinterpret_cast(p_value); + *value = VariantInternalAccessor::get(reinterpret_cast(p_variant)); + } +}; + #endif // VARIANT_INTERNAL_H diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index 8a261a88e3a..882256b7e34 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -174,7 +174,7 @@ void (*type_init_function_table[])(Variant *) = { &VariantInitializer::init, // STRING_NAME. &VariantInitializer::init, // NODE_PATH. &VariantInitializer::init, // RID. - &VariantTypeAdjust::adjust, // OBJECT. + &VariantInitializer::init, // OBJECT. &VariantInitializer::init, // CALLABLE. &VariantInitializer::init, // SIGNAL. &VariantInitializer::init, // DICTIONARY.