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:
loadFileData
loadImageColors
loadImagePalette
loadFontData (possibly, might never happen because its inputs can't be null from the Zig side)
loadCodepoints
loadMaterials
loadModelAnimations
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.
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'sptrCast
, 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.