Skip to content
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

Static methods in Godot API #43

Closed
Bromeon opened this issue Dec 8, 2022 · 2 comments · Fixed by #115
Closed

Static methods in Godot API #43

Bromeon opened this issue Dec 8, 2022 · 2 comments · Fixed by #115
Labels
c: engine Godot classes (nodes, resources, ...) feature Adds functionality to the library

Comments

@Bromeon
Copy link
Member

Bromeon commented Dec 8, 2022

Some Godot types are only constructible through static factory methods, e.g. DirAccess.open().

We could provide a method without self parameter, possibly reusing the singleton functionality.

let dir: Gd<DirAccess> = DirAccess::open("path".into());

We could in a later step also consider static user-provided methods (#[func]), in case GDExtension allows that.

@Bromeon Bromeon added feature Adds functionality to the library c: engine Godot classes (nodes, resources, ...) labels Dec 8, 2022
@ttencate
Copy link
Contributor

ttencate commented Feb 5, 2023

For starters, we could skip generating wrappers for static methods, to avoid accidents. Right now, this compiles even though Image::create is static (flagged in JSON as is_static: true), but it doesn't do what you expect:

let image = Image::new();
image.create(2, 4, false, Format::FORMAT_RGBA8);

Instead of initializing image, it creates and returns a new Image, and ends up leaking one of them as well:

WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
     at: cleanup (core/object/object.cpp:1982)
Leaked instance: Image:-9222503972424645408 - Resource path: 
Hint: Leaked instances typically happen when nodes are removed from the scene tree (with `remove_child()`) but not freed (with `free()` or `queue_free()`).

bors bot added a commit that referenced this issue Feb 5, 2023
115: Implement static methods for class + builtin methods r=Bromeon a=Bromeon

Also fixes a memory leak when `RefCounted` instances are returned from engine methods.

Closes #43.


Co-authored-by: Jan Haller <[email protected]>
@bors bors bot closed this as completed in eb5d43b Feb 5, 2023
@ttencate
Copy link
Contributor

ttencate commented Feb 5, 2023

Great work! 👏

ttencate pushed a commit to ttencate/gdext that referenced this issue Feb 5, 2023
115: Implement static methods for engine + builtin classes r=Bromeon a=Bromeon

Also fixes a memory leak when `RefCounted` instances are returned from engine methods.

Closes godot-rust#43.

Co-authored-by: Jan Haller <[email protected]>
ttencate pushed a commit to ttencate/gdext that referenced this issue Feb 5, 2023
115: Implement static methods for engine + builtin classes r=Bromeon a=Bromeon

Also fixes a memory leak when `RefCounted` instances are returned from engine methods.

Closes godot-rust#43.

Co-authored-by: Jan Haller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: engine Godot classes (nodes, resources, ...) feature Adds functionality to the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants