summaryrefslogtreecommitdiffstats
path: root/include/godot_cpp/classes
diff options
context:
space:
mode:
authorZhehang Ding <zhehangd@gmail.com>2023-02-15 22:36:29 -0800
committerZhehang Ding <zhehangd@gmail.com>2023-02-15 22:36:29 -0800
commit517db6686a11130293b1ddf644a5b5f472228807 (patch)
tree6bf6ed8ad27cbe967b017c5ae799ed230483fe32 /include/godot_cpp/classes
parentf5133c08a529d027e3232d593b0f6c3ca45a0545 (diff)
downloadredot-cpp-517db6686a11130293b1ddf644a5b5f472228807.tar.gz
Fix PtrToArg<Ref<T>> crash
Diffstat (limited to 'include/godot_cpp/classes')
-rw-r--r--include/godot_cpp/classes/ref.hpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/include/godot_cpp/classes/ref.hpp b/include/godot_cpp/classes/ref.hpp
index bac942f..af7711c 100644
--- a/include/godot_cpp/classes/ref.hpp
+++ b/include/godot_cpp/classes/ref.hpp
@@ -240,11 +240,11 @@ public:
template <class T>
struct PtrToArg<Ref<T>> {
_FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) {
- 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);
+ // Important: p_ptr is T*, not Ref<T>*, since Object* is what engine gives to ptrcall.
+ ERR_FAIL_NULL_V(p_ptr, Ref<T>());
+ 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)));
}
typedef Ref<T> EncodeT;
@@ -266,7 +266,10 @@ struct PtrToArg<const Ref<T> &> {
typedef Ref<T> EncodeT;
_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)));
+ ERR_FAIL_NULL_V(p_ptr, Ref<T>());
+ 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)));
}
};