Open
Description
Lately I've found a problem with GodotClass
es 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());
}