@@ -13,7 +13,7 @@ use crate::classes::{ClassDb, Object};
13
13
use crate :: meta:: CallContext ;
14
14
#[ cfg( debug_assertions) ]
15
15
use crate :: meta:: ClassName ;
16
- use crate :: obj:: { bounds, Bounds , Gd , GodotClass , InstanceId } ;
16
+ use crate :: obj:: { bounds, Bounds , Gd , GodotClass , InstanceId , RawGd } ;
17
17
use crate :: sys;
18
18
19
19
pub ( crate ) fn debug_string < T : GodotClass > (
@@ -23,12 +23,32 @@ 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
- write ! ( f, "{ty} {{ id: {id}, class: {class} }}" )
26
+ f. debug_struct ( ty)
27
+ . field ( "id" , & id)
28
+ . field ( "class" , & class)
29
+ . finish ( )
27
30
} else {
28
31
write ! ( f, "{ty} {{ freed obj }}" )
29
32
}
30
33
}
31
34
35
+ pub ( crate ) fn debug_string_nullable < T : GodotClass > (
36
+ obj : & RawGd < T > ,
37
+ f : & mut std:: fmt:: Formatter < ' _ > ,
38
+ ty : & str ,
39
+ ) -> std:: fmt:: Result {
40
+ if obj. is_null ( ) {
41
+ write ! ( f, "{ty} {{ null }}" )
42
+ } else {
43
+ // Unsafety introduced here to avoid creating a new Gd<T> (which can have all sorts of side effects, logs, refcounts etc.)
44
+ // *and* pushing down all high-level Gd<T> functions to RawGd<T> as pure delegates.
45
+
46
+ // SAFETY: layout of Gd<T> is currently equivalent to RawGd<T>.
47
+ let obj: & Gd < T > = unsafe { std:: mem:: transmute :: < & RawGd < T > , & Gd < T > > ( obj) } ;
48
+ debug_string ( obj, f, ty)
49
+ }
50
+ }
51
+
32
52
pub ( crate ) fn debug_string_with_trait < T : GodotClass > (
33
53
obj : & Gd < T > ,
34
54
f : & mut std:: fmt:: Formatter < ' _ > ,
@@ -37,7 +57,11 @@ pub(crate) fn debug_string_with_trait<T: GodotClass>(
37
57
) -> std:: fmt:: Result {
38
58
if let Some ( id) = obj. instance_id_or_none ( ) {
39
59
let class: StringName = obj. dynamic_class_string ( ) ;
40
- write ! ( f, "{ty} {{ id: {id}, class: {class}, trait: {trt} }}" )
60
+ f. debug_struct ( ty)
61
+ . field ( "id" , & id)
62
+ . field ( "class" , & class)
63
+ . field ( "trait" , & trt)
64
+ . finish ( )
41
65
} else {
42
66
write ! ( f, "{ty} {{ freed obj }}" )
43
67
}
@@ -83,7 +107,7 @@ pub(crate) fn ensure_object_alive(
83
107
// namely in PR https://github.com/godotengine/godot/pull/36189. Double-check to make sure.
84
108
assert_eq ! (
85
109
new_object_ptr, old_object_ptr,
86
- "{call_ctx}: instance ID {instance_id} points to a stale, reused object. Please report this to gdext maintainers."
110
+ "{call_ctx}: instance ID {instance_id} points to a stale, reused object. Please report this to godot-rust maintainers."
87
111
) ;
88
112
}
89
113
0 commit comments