@@ -240,11 +240,11 @@ class Ref {
240240template <class T >
241241struct PtrToArg <Ref<T>> {
242242 _FORCE_INLINE_ static Ref<T> convert (const void *p_ptr) {
243- GDExtensionRefPtr ref = (GDExtensionRefPtr) p_ptr;
244- ERR_FAIL_NULL_V (ref , Ref<T>());
245-
246- 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));
247- return Ref<T>(obj );
243+ // Important: p_ptr is T*, not Ref<T>*, since Object* is what engine gives to ptrcall.
244+ ERR_FAIL_NULL_V (p_ptr , Ref<T>());
245+ return Ref<T>( reinterpret_cast <T *>(godot::internal::gde_interface-> object_get_instance_binding (
246+ reinterpret_cast <GDExtensionObjectPtr>( const_cast < void *>(p_ptr)),
247+ godot::internal::token, &T::___binding_callbacks)) );
248248 }
249249
250250 typedef Ref<T> EncodeT;
@@ -266,7 +266,10 @@ struct PtrToArg<const Ref<T> &> {
266266 typedef Ref<T> EncodeT;
267267
268268 _FORCE_INLINE_ static Ref<T> convert (const void *p_ptr) {
269- 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)));
269+ ERR_FAIL_NULL_V (p_ptr, Ref<T>());
270+ return Ref<T>(reinterpret_cast <T *>(godot::internal::gde_interface->object_get_instance_binding (
271+ reinterpret_cast <GDExtensionObjectPtr>(const_cast <void *>(p_ptr)),
272+ godot::internal::token, &T::___binding_callbacks)));
270273 }
271274};
272275
0 commit comments