Skip to content

Commit

Permalink
-Attempts to fix godot-rust#138. Revert of ac02be1.
Browse files Browse the repository at this point in the history
  • Loading branch information
thebigG committed Mar 10, 2023
1 parent 55c4d3a commit 3321bca
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion godot-core/src/builtin/meta/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions godot-core/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
3 changes: 2 additions & 1 deletion godot-core/src/obj/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ impl<T: GodotClass> Base<T> {
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)
Expand Down
10 changes: 8 additions & 2 deletions godot-core/src/obj/gd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ where
where
T: cap::GodotInit,
{
unsafe {
let result = unsafe {
let object_ptr = callbacks::create::<T>(ptr::null_mut());
Gd::from_obj_sys(object_ptr)
};


T::Mem::maybe_init_ref(&result);
result
}
}



/// Creates a `Gd<T>` using a function that constructs a `T` from a provided base.
///
Expand Down

0 comments on commit 3321bca

Please sign in to comment.