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

Use handles instead of pointers #32

Open
Andre-LA opened this issue Apr 17, 2023 · 0 comments
Open

Use handles instead of pointers #32

Andre-LA opened this issue Apr 17, 2023 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@Andre-LA
Copy link
Owner

Andre-LA commented Apr 17, 2023

Currently, SDL resources are handled with pointers directly, with this the API inherits all the risks associated with pointers, like use-after-free, double-free, dangling pointers, etc.

Also, there's some needed care in order to generate bindings correctly for these pointers.

nene/include/nene/font.h

Lines 18 to 20 in 407a276

typedef struct nene_Font {
TTF_Font *raw;
} nene_Font;

Of course, pointers are a essential when programming games, especially in performance-sensitive code, however, one of the major goals of Nene it's to make game programming simpler (quite like when programming a game on a scripting language).

Thus, on the API side, Nene will stop using pointers and change for generational indexes.

This concept are described on some blogposts, in general, "floooh" described very well this concept on Handles are the better pointers article.

With that, not only binding generation gets simpler and usage gets safer, it would also be possible to detect use-after-frees, double-frees, etc. with runtime checking, and general shutdown gets simpler with no leaks.

The downside it's the performance price, but again, Nene it's meant for quite simple (or just average) indie games, not a million-objects benchmark.

@Andre-LA Andre-LA added the enhancement New feature or request label Apr 17, 2023
@Andre-LA Andre-LA added this to the v0.4.0 milestone May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant