File tree Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -264,21 +264,33 @@ pub mod mem {
264
264
impl Memory for DynamicRefCount {
265
265
fn maybe_init_ref < T : GodotClass > ( obj : & Gd < T > ) {
266
266
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)
269
273
}
270
274
}
271
275
272
276
fn maybe_inc_ref < T : GodotClass > ( obj : & Gd < T > ) {
273
277
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)
276
284
}
277
285
}
278
286
279
287
fn maybe_dec_ref < T : GodotClass > ( obj : & Gd < T > ) -> bool {
280
288
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
+ {
282
294
StaticRefCount :: maybe_dec_ref ( obj)
283
295
} else {
284
296
false
Original file line number Diff line number Diff line change @@ -531,6 +531,16 @@ fn object_engine_manual_free() {
531
531
} // drop(node)
532
532
}
533
533
534
+ /// Tests the [`DynamicRefCount`] destructor when the underlying [`Object`] is already freed.
535
+ #[ itest]
536
+ fn object_engine_shared_free ( ) {
537
+ {
538
+ let node = Node :: new_alloc ( ) ;
539
+ let _object = node. share ( ) . upcast :: < Object > ( ) ;
540
+ node. free ( ) ;
541
+ } // drop(_object)
542
+ }
543
+
534
544
#[ itest]
535
545
fn object_engine_manual_double_free ( ) {
536
546
expect_panic ( "double free()" , || {
You can’t perform that action at this time.
0 commit comments