From 3d237fc7d7956bf805d005833dc1687971ee452a Mon Sep 17 00:00:00 2001 From: ondy-personal <98788662+ondy-personal@users.noreply.github.com> Date: Mon, 31 Jan 2022 17:12:45 -0800 Subject: [PATCH] Fixed crash when called methods return nullptr. The returned value "ret" may be nullptr in which case the code would crash because "object_get_instance_binding" can't be called on nullptr input. This should be very easy to reproduce, I encountered it pretty much any time I called a method that returned Ref. E.g.: Ref instance; instance.instantiate(); instance.get_mesh(); // Crash because no mesh was set for the instance and the returned value was nullptr. --- include/godot_cpp/core/engine_ptrcall.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/godot_cpp/core/engine_ptrcall.hpp b/include/godot_cpp/core/engine_ptrcall.hpp index 379d0026..7ed258e7 100644 --- a/include/godot_cpp/core/engine_ptrcall.hpp +++ b/include/godot_cpp/core/engine_ptrcall.hpp @@ -48,6 +48,9 @@ O *_call_native_mb_ret_obj(const GDNativeMethodBindPtr mb, void *instance, const GodotObject *ret = nullptr; std::array mb_args = { { (const GDNativeTypePtr)args... } }; internal::gdn_interface->object_method_bind_ptrcall(mb, instance, mb_args.data(), &ret); + if (ret == nullptr) { + return nullptr; + } return reinterpret_cast(internal::gdn_interface->object_get_instance_binding(ret, internal::token, &O::___binding_callbacks)); }