Not-Nik / raylib-zig

Manually tweaked, auto-generated raylib bindings for zig. https://github.com/raysan5/raylib
MIT License
623 stars 115 forks source link

Apps crash when functions that return arrays, return null pointers #49

Closed Not-Nik closed 1 year ago

Not-Nik commented 1 year ago

Sometimes raylib functions return NULL. This is mostly fine in pure C, because raylib is designed around this; it handles these null values properly. With Zig's ptrCast, however, it is undefined behaviour to cast a null pointer to a non-optional pointer and it checks this in debug builds, resulting in panics and crashes.

This affects all of the following:

Other functions returning arrays would either crash (segfault) before returning, because they use the arrays they return, or simply never return null pointers.

One simple way to address this, is to add an error type to each of these functions and check for null pointers. I am pretty sure that this would not affect the raylib feel of the binding, because if you've used these functions in C you are either an advanced user (font data, codepoints, extra materials, animations) or needed to check for null pointers anyways (file data).

Either way, I would like to postpone these fixes until Zig 0.11.0 is released and #48 is merged, so that I don't have to maintain two branches and push everything twice.

CodesOtakuYT commented 1 year ago

Zig 0.11.0 is released and https://github.com/Not-Nik/raylib-zig/pull/48 is merged, any news?