File tree Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -23,10 +23,13 @@ pub(crate) fn debug_string<T: GodotClass>(
23
23
) -> std:: fmt:: Result {
24
24
if let Some ( id) = obj. instance_id_or_none ( ) {
25
25
let class: StringName = obj. dynamic_class_string ( ) ;
26
- f. debug_struct ( ty)
27
- . field ( "id" , & id)
28
- . field ( "class" , & class)
29
- . finish ( )
26
+
27
+ let mut builder = f. debug_struct ( ty) ;
28
+ builder. field ( "id" , & id) . field ( "class" , & class) ;
29
+ if let Some ( refcount) = obj. maybe_refcount ( ) {
30
+ builder. field ( "refc" , & refcount) ;
31
+ }
32
+ builder. finish ( )
30
33
} else {
31
34
write ! ( f, "{ty} {{ freed obj }}" )
32
35
}
@@ -57,11 +60,16 @@ pub(crate) fn debug_string_with_trait<T: GodotClass>(
57
60
) -> std:: fmt:: Result {
58
61
if let Some ( id) = obj. instance_id_or_none ( ) {
59
62
let class: StringName = obj. dynamic_class_string ( ) ;
60
- f. debug_struct ( ty)
63
+
64
+ let mut builder = f. debug_struct ( ty) ;
65
+ builder
61
66
. field ( "id" , & id)
62
67
. field ( "class" , & class)
63
- . field ( "trait" , & trt)
64
- . finish ( )
68
+ . field ( "trait" , & trt) ;
69
+ if let Some ( refcount) = obj. maybe_refcount ( ) {
70
+ builder. field ( "refc" , & refcount) ;
71
+ }
72
+ builder. finish ( )
65
73
} else {
66
74
write ! ( f, "{ty} {{ freed obj }}" )
67
75
}
Original file line number Diff line number Diff line change @@ -302,6 +302,15 @@ impl<T: GodotClass> Gd<T> {
302
302
}
303
303
}
304
304
305
+ /// Returns the reference count, if the dynamic object inherits `RefCounted`; and `None` otherwise.
306
+ pub ( crate ) fn maybe_refcount ( & self ) -> Option < usize > {
307
+ // Fast check if ref-counted without downcast.
308
+ self . instance_id_unchecked ( ) . is_ref_counted ( ) . then ( || {
309
+ let rc = self . raw . with_ref_counted ( |refc| refc. get_reference_count ( ) ) ;
310
+ rc as usize
311
+ } )
312
+ }
313
+
305
314
/// **Upcast:** convert into a smart pointer to a base class. Always succeeds.
306
315
///
307
316
/// Moves out of this value. If you want to create _another_ smart pointer instance,
You can’t perform that action at this time.
0 commit comments