diff --git a/core/object/ref_counted.h b/core/object/ref_counted.h index 58706fb9a93..33865147067 100644 --- a/core/object/ref_counted.h +++ b/core/object/ref_counted.h @@ -242,8 +242,11 @@ public: template struct PtrToArg> { _FORCE_INLINE_ static Ref convert(const void *p_ptr) { + if (p_ptr == nullptr) { + return Ref(); + } // p_ptr points to a RefCounted object - return Ref(const_cast(reinterpret_cast(p_ptr))); + return Ref(const_cast(*reinterpret_cast(p_ptr))); } typedef Ref EncodeT; @@ -259,8 +262,11 @@ struct PtrToArg &> { typedef Ref EncodeT; _FORCE_INLINE_ static Ref convert(const void *p_ptr) { + if (p_ptr == nullptr) { + return Ref(); + } // p_ptr points to a RefCounted object - return Ref((T *)p_ptr); + return Ref(*((T *const *)p_ptr)); } }; diff --git a/core/variant/method_ptrcall.h b/core/variant/method_ptrcall.h index df1e524494d..cbfb9cc257d 100644 --- a/core/variant/method_ptrcall.h +++ b/core/variant/method_ptrcall.h @@ -159,7 +159,10 @@ MAKE_PTRARG_BY_REFERENCE(Variant); template struct PtrToArg { _FORCE_INLINE_ static T *convert(const void *p_ptr) { - return const_cast(reinterpret_cast(p_ptr)); + if (p_ptr == nullptr) { + return nullptr; + } + return const_cast(*reinterpret_cast(p_ptr)); } typedef Object *EncodeT; _FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) { @@ -170,7 +173,10 @@ struct PtrToArg { template struct PtrToArg { _FORCE_INLINE_ static const T *convert(const void *p_ptr) { - return reinterpret_cast(p_ptr); + if (p_ptr == nullptr) { + return nullptr; + } + return *reinterpret_cast(p_ptr); } typedef const Object *EncodeT; _FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) { diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h index 8013c1a32a8..c23066c0c67 100644 --- a/core/variant/variant_internal.h +++ b/core/variant/variant_internal.h @@ -502,7 +502,7 @@ public: case Variant::PACKED_COLOR_ARRAY: return get_color_array(v); case Variant::OBJECT: - return v->_get_obj().obj; + return get_object(v); case Variant::VARIANT_MAX: ERR_FAIL_V(nullptr); } diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 7c6328e922a..e4999a90c87 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -2889,7 +2889,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() { itype.cs_out = "%5return (%2)%0(%1);"; - itype.c_arg_in = "(void*)%s"; + itype.c_arg_in = "&%s"; itype.c_type = "IntPtr"; itype.c_type_in = itype.c_type; itype.c_type_out = "GodotObject";