diff --git a/godot-core/src/builtin/meta/signature.rs b/godot-core/src/builtin/meta/signature.rs index 415f8f1d4..4fa286c65 100644 --- a/godot-core/src/builtin/meta/signature.rs +++ b/godot-core/src/builtin/meta/signature.rs @@ -163,7 +163,7 @@ macro_rules! impl_signature_for_tuple { .unwrap_or_else(|e| return_error::<$R>(method_name, &e)); // FIXME is inc_ref needed here? - // std::mem::forget(ret_val); + std::mem::forget(ret_val); } } }; diff --git a/godot-core/src/macros.rs b/godot-core/src/macros.rs index 26f76f969..a8a625aec 100644 --- a/godot-core/src/macros.rs +++ b/godot-core/src/macros.rs @@ -414,7 +414,7 @@ macro_rules! gdext_ptrcall { <$($RetTy)+ as sys::GodotFfi>::write_sys(&ret_val, $ret); // FIXME is inc_ref needed here? - // #[allow(clippy::forget_copy)] - // std::mem::forget(ret_val); + #[allow(clippy::forget_copy)] + std::mem::forget(ret_val); }; } diff --git a/godot-core/src/obj/base.rs b/godot-core/src/obj/base.rs index 4844d4c25..e83345f7a 100644 --- a/godot-core/src/obj/base.rs +++ b/godot-core/src/obj/base.rs @@ -40,7 +40,8 @@ impl Base { assert!(!base_ptr.is_null(), "instance base is null pointer"); // Initialize only as weak pointer (don't increment reference count) - let obj = Gd::from_obj_sys_weak(base_ptr); + + let obj = Gd::from_obj_sys(base_ptr); // This obj does not contribute to the strong count, otherwise we create a reference cycle: // 1. RefCounted (dropped in GDScript) diff --git a/godot-core/src/obj/gd.rs b/godot-core/src/obj/gd.rs index 38554dbe1..5c8433eda 100644 --- a/godot-core/src/obj/gd.rs +++ b/godot-core/src/obj/gd.rs @@ -86,11 +86,17 @@ where where T: cap::GodotInit, { - unsafe { + let result = unsafe { let object_ptr = callbacks::create::(ptr::null_mut()); Gd::from_obj_sys(object_ptr) + }; + + + T::Mem::maybe_init_ref(&result); + result } - } + + /// Creates a `Gd` using a function that constructs a `T` from a provided base. ///