summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDavid Snopek <dsnopek@gmail.com>2024-04-29 16:46:46 -0500
committerGitHub <noreply@github.com>2024-04-29 16:46:46 -0500
commit2cd3d3910881ed38c6f7a88fe74da98ebc440a09 (patch)
treec2cf440085de1efc61d0ebe8abc45c5348058d3d /include
parent1d829f2e4a422cd40739cbfb9fbff2a64ddb6d13 (diff)
parent37542dc2ec1e98fbe93e2daa8f11e7fb5428cb0e (diff)
downloadredot-cpp-2cd3d3910881ed38c6f7a88fe74da98ebc440a09.tar.gz
Merge pull request #1405 from dsnopek/fix-null-object-arguments
Correctly handle `Object *` arguments that were encoded as `nullptr`
Diffstat (limited to 'include')
-rw-r--r--include/godot_cpp/core/method_ptrcall.hpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/include/godot_cpp/core/method_ptrcall.hpp b/include/godot_cpp/core/method_ptrcall.hpp
index ca3327e..b12a7e6 100644
--- a/include/godot_cpp/core/method_ptrcall.hpp
+++ b/include/godot_cpp/core/method_ptrcall.hpp
@@ -170,11 +170,11 @@ template <typename T>
struct PtrToArg<T *> {
static_assert(std::is_base_of<Object, T>::value, "Cannot encode non-Object value as an Object");
_FORCE_INLINE_ static T *convert(const void *p_ptr) {
- return reinterpret_cast<T *>(godot::internal::get_object_instance_binding(*reinterpret_cast<GDExtensionObjectPtr *>(const_cast<void *>(p_ptr))));
+ return likely(p_ptr) ? reinterpret_cast<T *>(godot::internal::get_object_instance_binding(*reinterpret_cast<GDExtensionObjectPtr *>(const_cast<void *>(p_ptr)))) : nullptr;
}
typedef Object *EncodeT;
_FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {
- *reinterpret_cast<const void **>(p_ptr) = p_var ? p_var->_owner : nullptr;
+ *reinterpret_cast<const void **>(p_ptr) = likely(p_var) ? p_var->_owner : nullptr;
}
};
@@ -182,11 +182,11 @@ template <typename T>
struct PtrToArg<const T *> {
static_assert(std::is_base_of<Object, T>::value, "Cannot encode non-Object value as an Object");
_FORCE_INLINE_ static const T *convert(const void *p_ptr) {
- return reinterpret_cast<const T *>(godot::internal::get_object_instance_binding(*reinterpret_cast<GDExtensionObjectPtr *>(const_cast<void *>(p_ptr))));
+ return likely(p_ptr) ? reinterpret_cast<const T *>(godot::internal::get_object_instance_binding(*reinterpret_cast<GDExtensionObjectPtr *>(const_cast<void *>(p_ptr)))) : nullptr;
}
typedef const Object *EncodeT;
_FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) {
- *reinterpret_cast<const void **>(p_ptr) = p_var ? p_var->_owner : nullptr;
+ *reinterpret_cast<const void **>(p_ptr) = likely(p_var) ? p_var->_owner : nullptr;
}
};