nene icon indicating copy to clipboard operation
nene copied to clipboard

Use handles instead of pointers

Open Andre-LA opened this issue 1 year ago • 0 comments

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.

https://github.com/Andre-LA/nene/blob/407a276d77bb19c7fed9d45f03f9b5c7231ad4b6/include/nene/font.h#L18-L20

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 avatar Apr 17 '23 19:04 Andre-LA