summaryrefslogtreecommitdiffstats
path: root/include/godot_cpp/classes
diff options
context:
space:
mode:
authorBastiaan Olij <mux213@gmail.com>2022-12-11 23:20:14 +1100
committerBastiaan Olij <mux213@gmail.com>2022-12-13 10:41:55 +1100
commit992d85e6f845d798ab26237fe52d1aa6461452c5 (patch)
tree2dbb3a98b723c02b03a0801b6fd660f7320b5c46 /include/godot_cpp/classes
parentc21705982e8d58c46cc0b359d6986fd4f88f2612 (diff)
downloadredot-cpp-992d85e6f845d798ab26237fe52d1aa6461452c5.tar.gz
Fix virtual GDExtension method Ref<T> conversion
Diffstat (limited to 'include/godot_cpp/classes')
-rw-r--r--include/godot_cpp/classes/ref.hpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/include/godot_cpp/classes/ref.hpp b/include/godot_cpp/classes/ref.hpp
index 4e2eb49..5a26548 100644
--- a/include/godot_cpp/classes/ref.hpp
+++ b/include/godot_cpp/classes/ref.hpp
@@ -240,13 +240,24 @@ public:
template <class T>
struct PtrToArg<Ref<T>> {
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
- return Ref<T>(reinterpret_cast<T *>(godot::internal::gde_interface->object_get_instance_binding(*reinterpret_cast<GDExtensionObjectPtr *>(const_cast<void *>(p_ptr)), godot::internal::token, &T::___binding_callbacks)));
+ GDExtensionRefPtr ref = (GDExtensionRefPtr)p_ptr;
+ ERR_FAIL_NULL_V(ref, Ref<T>());
+
+ T *obj = reinterpret_cast<T *>(godot::internal::gde_interface->object_get_instance_binding(godot::internal::gde_interface->ref_get_object(ref), godot::internal::token, &T::___binding_callbacks));
+ return Ref<T>(obj);
}
typedef Ref<T> EncodeT;
_FORCE_INLINE_ static void encode(Ref<T> p_val, void *p_ptr) {
- *reinterpret_cast<const GodotObject **>(p_ptr) = p_val->_owner;
+ GDExtensionRefPtr ref = (GDExtensionRefPtr)p_ptr;
+ ERR_FAIL_NULL(ref);
+
+ // This code assumes that p_ptr points to an unset Ref<T> variable on the Godot side
+ // so we only set it if we have an object to set.
+ if (p_val.is_valid()) {
+ godot::internal::gde_interface->ref_set_object(ref, p_val->_owner);
+ }
}
};