Skip to content

Commit 01f2cb3

Browse files
committed
Add ElementType::base_class_id()
1 parent 1fd5853 commit 01f2cb3

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

godot-core/src/meta/element_type.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,7 @@ impl ElementType {
7070
pub fn class_id(&self) -> Option<ClassId> {
7171
match self {
7272
ElementType::Class(class_name) => Some(*class_name),
73-
ElementType::ScriptClass(script) => {
74-
// For script classes, we return the native base class name
75-
script.script().map(|s| {
76-
let base_type = s.get_instance_base_type();
77-
ClassId::new_dynamic(base_type.to_string())
78-
})
79-
}
73+
ElementType::ScriptClass(script) => script.base_class_id(),
8074
_ => None,
8175
}
8276
}
@@ -228,4 +222,14 @@ impl ElementScript {
228222
// Note: might also fail in the future if acquired on another thread.
229223
Gd::try_from_instance_id(self.script_instance_id).ok()
230224
}
225+
226+
/// Returns the native base class of the script.
227+
///
228+
/// Typically, this corresponds to the class mentioned in `extends` in GDScript.
229+
pub fn base_class_id(&self) -> Option<ClassId> {
230+
self.script().map(|s| {
231+
let base_type = s.get_instance_base_type();
232+
ClassId::new_dynamic(base_type.to_string())
233+
})
234+
}
231235
}

godot-core/src/obj/gd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,8 @@ where
748748
sys::interface_fn!(object_destroy)(self.raw.obj_sys());
749749
}
750750

751-
// TODO: this might leak associated data in Gd<T>, e.g. ClassId.
752-
std::mem::forget(self);
751+
// Deallocate associated data in Gd, without destroying the object pointer itself (already done above).
752+
self.drop_weak()
753753
}
754754
}
755755

0 commit comments

Comments
 (0)