From f08bc0df7c16a6d12292628ec8cc2e015047c450 Mon Sep 17 00:00:00 2001 From: Ruslan Mustakov Date: Sat, 19 Aug 2017 19:41:11 +0700 Subject: Construct Variants from Reference properly in GDNative Previously godot_variant_new_object constructed Variant without accounting for the fact that the Object can be a Reference, so refcount was not increased and References were destructed prematurely. Also, Reference::init_ref did not propagate refcount increment to the script instance, which led to desync of refcount info on the script side and Godot side. --- core/variant.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/variant.cpp') diff --git a/core/variant.cpp b/core/variant.cpp index 74f6b6a711..10d86152ee 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -2259,8 +2259,8 @@ Variant::Variant(const RefPtr &p_resource) { type = OBJECT; memnew_placement(_data._mem, ObjData); - REF ref = p_resource; - _get_obj().obj = ref.ptr(); + REF *ref = reinterpret_cast(p_resource.get_data()); + _get_obj().obj = ref->ptr(); _get_obj().ref = p_resource; } -- cgit v1.2.3