summaryrefslogtreecommitdiff
path: root/modules/gdnative
diff options
context:
space:
mode:
authorThomas Herzog <thomas.herzog@mail.com>2017-09-14 21:21:50 +0200
committerGitHub <noreply@github.com>2017-09-14 21:21:50 +0200
commit5636ac526e1d9b211700ec2386c2a01c2419d1f7 (patch)
tree2e0d5c7c4ca65fbe857e1e8586314adb1d2c3fe5 /modules/gdnative
parent35ed1eef2a6a00087799ded7e10ce94ed4d8b373 (diff)
parentf08bc0df7c16a6d12292628ec8cc2e015047c450 (diff)
Merge pull request #11237 from endragor/gdnative-variant-ref
Construct Variants from Reference properly in GDNative
Diffstat (limited to 'modules/gdnative')
-rw-r--r--modules/gdnative/gdnative/variant.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/modules/gdnative/gdnative/variant.cpp b/modules/gdnative/gdnative/variant.cpp
index b61f80b1f9..1b2aae607f 100644
--- a/modules/gdnative/gdnative/variant.cpp
+++ b/modules/gdnative/gdnative/variant.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "gdnative/variant.h"
+#include "core/reference.h"
#include "core/variant.h"
#ifdef __cplusplus
@@ -158,7 +159,21 @@ void GDAPI godot_variant_new_rid(godot_variant *r_dest, const godot_rid *p_rid)
void GDAPI godot_variant_new_object(godot_variant *r_dest, const godot_object *p_obj) {
Variant *dest = (Variant *)r_dest;
Object *obj = (Object *)p_obj;
- memnew_placement_custom(dest, Variant, Variant(obj));
+ Reference *reference = Object::cast_to<Reference>(obj);
+ REF ref;
+ if (reference) {
+ ref = REF(reference);
+ }
+ if (!ref.is_null()) {
+ memnew_placement_custom(dest, Variant, Variant(ref.get_ref_ptr()));
+ } else {
+#if defined(DEBUG_METHODS_ENABLED)
+ if (reference) {
+ ERR_PRINT("Reference object has 0 refcount in godot_variant_new_object - you lost it somewhere.");
+ }
+#endif
+ memnew_placement_custom(dest, Variant, Variant(obj));
+ }
}
void GDAPI godot_variant_new_dictionary(godot_variant *r_dest, const godot_dictionary *p_dict) {