Skip to content

Commit f9f3d3b

Browse files
Use instance_id_or_none in DynamicRefCount
1 parent 54cb201 commit f9f3d3b

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

godot-core/src/obj/traits.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,21 +264,33 @@ pub mod mem {
264264
impl Memory for DynamicRefCount {
265265
fn maybe_init_ref<T: GodotClass>(obj: &Gd<T>) {
266266
out!(" Dyn::init <{}>", std::any::type_name::<T>());
267-
if obj.instance_id().is_ref_counted() {
268-
StaticRefCount::maybe_init_ref(obj);
267+
if obj
268+
.instance_id_or_none()
269+
.map(|id| id.is_ref_counted())
270+
.unwrap_or(false)
271+
{
272+
StaticRefCount::maybe_init_ref(obj)
269273
}
270274
}
271275

272276
fn maybe_inc_ref<T: GodotClass>(obj: &Gd<T>) {
273277
out!(" Dyn::inc <{}>", std::any::type_name::<T>());
274-
if obj.instance_id().is_ref_counted() {
275-
StaticRefCount::maybe_inc_ref(obj);
278+
if obj
279+
.instance_id_or_none()
280+
.map(|id| id.is_ref_counted())
281+
.unwrap_or(false)
282+
{
283+
StaticRefCount::maybe_inc_ref(obj)
276284
}
277285
}
278286

279287
fn maybe_dec_ref<T: GodotClass>(obj: &Gd<T>) -> bool {
280288
out!(" Dyn::dec <{}>", std::any::type_name::<T>());
281-
if obj.instance_id().is_ref_counted() {
289+
if obj
290+
.instance_id_or_none()
291+
.map(|id| id.is_ref_counted())
292+
.unwrap_or(false)
293+
{
282294
StaticRefCount::maybe_dec_ref(obj)
283295
} else {
284296
false

0 commit comments

Comments
 (0)