Not-Nik / raylib-zig

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

loadImageColors problem #85

Closed gamecubate closed 2 months ago

gamecubate commented 2 months ago

I am new at Zig and I suspect that the problem comes from me. My code won't compile and the error message is difficult to understand.

Raylib's LoadImageColors is defined like this:

Color *LoadImageColors(Image image);  // Load color data from image as a Color array (RGBA - 32bit)

In my code, I invoke it like that:

const pixels: [*c]rl.Color = rl.loadImageColors(img);

The error message I get is this:

src/main.zig:41:51: error: expected type '[*c]raylib.Color', found '@typeInfo(@typeInfo(@TypeOf(raylib.loadImageColors)).Fn.return_type.?).ErrorUnion.error_set![]raylib.Color'
    const pixels: [*]rl.Color = rl.loadImageColors(img);

Am I calling this wrong or have I found a bug?

Not-Nik commented 2 months ago

You are calling it wrongly. As the error message states loadImageColors returns a ![]Color, not a [*]Color. This is because the binding knows that the function returns an array, and converts it to a slice for you. The error message is indeed a bit confusing, because the error type is not specified in the function header.