From 517db6686a11130293b1ddf644a5b5f472228807 Mon Sep 17 00:00:00 2001 From: Zhehang Ding Date: Wed, 15 Feb 2023 22:36:29 -0800 Subject: [PATCH] Fix PtrToArg> crash --- include/godot_cpp/classes/ref.hpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/include/godot_cpp/classes/ref.hpp b/include/godot_cpp/classes/ref.hpp index bac942fd..af7711c5 100644 --- a/include/godot_cpp/classes/ref.hpp +++ b/include/godot_cpp/classes/ref.hpp @@ -240,11 +240,11 @@ public: template struct PtrToArg> { _FORCE_INLINE_ static Ref convert(const void *p_ptr) { - GDExtensionRefPtr ref = (GDExtensionRefPtr)p_ptr; - ERR_FAIL_NULL_V(ref, Ref()); - - T *obj = reinterpret_cast(godot::internal::gde_interface->object_get_instance_binding(godot::internal::gde_interface->ref_get_object(ref), godot::internal::token, &T::___binding_callbacks)); - return Ref(obj); + // Important: p_ptr is T*, not Ref*, since Object* is what engine gives to ptrcall. + ERR_FAIL_NULL_V(p_ptr, Ref()); + return Ref(reinterpret_cast(godot::internal::gde_interface->object_get_instance_binding( + reinterpret_cast(const_cast(p_ptr)), + godot::internal::token, &T::___binding_callbacks))); } typedef Ref EncodeT; @@ -266,7 +266,10 @@ struct PtrToArg &> { typedef Ref EncodeT; _FORCE_INLINE_ static Ref convert(const void *p_ptr) { - return Ref(reinterpret_cast(godot::internal::gde_interface->object_get_instance_binding(*reinterpret_cast(const_cast(p_ptr)), godot::internal::token, &T::___binding_callbacks))); + ERR_FAIL_NULL_V(p_ptr, Ref()); + return Ref(reinterpret_cast(godot::internal::gde_interface->object_get_instance_binding( + reinterpret_cast(const_cast(p_ptr)), + godot::internal::token, &T::___binding_callbacks))); } };