-
-
Notifications
You must be signed in to change notification settings - Fork 287
Problems with reference count on using custom singletons inheriting from RefCounted #522
Copy link
Copy link
Open
Labels
bugc: engineGodot classes (nodes, resources, ...)Godot classes (nodes, resources, ...)ubUndefined behaviorUndefined behavior
Description
Lately I've found a problem with GodotClasses thats are to be saved as singleton. During discussion with @lilizoey we were able to pinpoint the possible problem: it seems that gdext decreases the reference count too eagerly. Below is an example:
#[itest(focus)]
fn test_refcount_singleton() {
#[derive(godot::prelude::GodotClass)]
#[class(init, base=RefCounted)]
struct SingletonTest;
use godot::obj::UserClass;
let mut engine = godot::engine::Engine::singleton();
let singleton = SingletonTest::new_gd();
engine.register_singleton("SingletonTest".into(), singleton.clone().upcast());
// Uncommenting line below makes the test pass.
// std::mem::forget(singleton);
engine.get_singleton("SingletonTest".into());
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugc: engineGodot classes (nodes, resources, ...)Godot classes (nodes, resources, ...)ubUndefined behaviorUndefined behavior