Fix unset ObjectID with validated get_object() call

Fixes unset `ObjectID` in variant when calling a validated builtin method returning an `Object *`.
This commit is contained in:
rune-scape 2022-09-28 23:04:22 -07:00
parent f8745f2f71
commit 51c411c7ad

View file

@ -1047,7 +1047,7 @@ struct VariantInternalAccessor<PackedColorArray> {
template <>
struct VariantInternalAccessor<Object *> {
static _FORCE_INLINE_ Object *get(const Variant *v) { return const_cast<Object *>(*VariantInternal::get_object(v)); }
static _FORCE_INLINE_ void set(Variant *v, const Object *p_value) { *VariantInternal::get_object(v) = const_cast<Object *>(p_value); }
static _FORCE_INLINE_ void set(Variant *v, const Object *p_value) { VariantInternal::object_assign(v, p_value); }
};
template <>
@ -1532,27 +1532,4 @@ struct VariantTypeConstructor {
}
};
template <>
struct VariantTypeConstructor<Object *> {
_FORCE_INLINE_ static void variant_from_type(void *p_variant, void *p_value) {
Variant *variant = reinterpret_cast<Variant *>(p_variant);
VariantInitializer<Object *>::init(variant);
Object *object = *(reinterpret_cast<Object **>(p_value));
if (object) {
if (object->is_ref_counted()) {
if (!VariantInternal::initialize_ref(object)) {
return;
}
}
VariantInternalAccessor<Object *>::set(variant, object);
VariantInternalAccessor<ObjectID>::set(variant, object->get_instance_id());
}
}
_FORCE_INLINE_ static void type_from_variant(void *p_value, void *p_variant) {
Object **value = reinterpret_cast<Object **>(p_value);
*value = VariantInternalAccessor<Object *>::get(reinterpret_cast<Variant *>(p_variant));
}
};
#endif // VARIANT_INTERNAL_H