Skip to content

Commit 553c168

Browse files
committed
drop_strong_ref – make sure that given instance haven't been freed before dropping stored StrongRef.
1 parent 7118691 commit 553c168

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

godot-core/src/obj/base.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,13 @@ impl<T: GodotClass> Base<T> {
246246
"Base unexpectedly had its strong ref rug-pulled"
247247
);
248248

249+
// Editor creates instances of given class for various purposes (getting class docs, default values...)
250+
// and frees them instantly before our callable can be executed.
251+
// Perform "weak" drop instead of "strong" one iff our instance is no longer valid.
252+
if !instance_id.lookup_validity() {
253+
strong_ref.unwrap().drop_weak();
254+
}
255+
249256
// Triggers RawGd::drop() -> dec-ref -> possibly object destruction.
250257
});
251258
}

0 commit comments

Comments
 (0)