-
-
Notifications
You must be signed in to change notification settings - Fork 23.6k
Preparation to fix memory leak when using Ref in NativeScript #33532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Some context is needed here. In C++ bindings, we instanciate new classes with The problem arises when we want to instance custom classes, from our C++ library. First, we need to get a hand on the So in my opinion, those PRs solve the problem in the wrong way. They rely on the existence of complicated workarounds, which should not have been there in the first place. |
|
It's possible to setup the script instance of an |
|
@toasteater interesting... but then how do you get a hand on your custom class instance pointer? |
|
@Zylann Call |
|
@toasteater like so? template <class T>
T *get_custom_class_instance(const Object *obj) {
return (obj) ? (T *)godot::nativescript_api->godot_nativescript_get_userdata(obj->_owner) : nullptr;
}
template <class T>
inline T *create_custom_class_instance(const char *class_name) {
godot::NativeScript *script = godot::NativeScript::_new();
script->set_library(get_wrapper<godot::GDNativeLibrary>((godot_object *)godot::gdnlib));
script->set_class_name(class_name);
// This makes Godot create the custom class instance and attach it to a new instance of the base class
Object *base_obj = T::___new_godot_base();
base_obj->set_script(script);
T *instance = get_custom_class_instance(base_obj);
return instance;
}I need to check if it works properly. Notably, I wonder if the |
|
@Zylann Yes. The Rust bindings do something like that and it seems to work. I don't think you want to free |
|
@toasteater what I mean is like I explained earlier, |
|
@Zylann The wrapper itself is probably not needed, since whatever magic in your |
|
@PhilWun Is this still desired? If so, it needs to be rebased on the latest master branch. The commits you pushed are merge commits, which are not good to have in a PR. See this article to learn how to rebase: https://docs.godotengine.org/en/latest/community/contributing/pr_workflow.html#mastering-the-pr-workflow-the-rebase |
|
The bug that led to this PR has been fixed, so it's probably no longer necessary. |
|
Closing then. Please comment if it's still necessary and we can reopen it. |
Preparation to fix godotengine/godot-cpp#215.