I also got that error.
I modified the source to to make it more similar like other lines and with that I got a few similar errors.fileDataPtr += @as(usize, @sizeOf(c_int));
(I currently don’t know why these don’t get generated correctly, automatically)
After that it compiled and segfaulted, because of a null pointer being dereferenced.
I had to change the code to:
...
const rec = ray.Rectangle{ .x = 600, .y = 40, .width = 120, .height = 20 };
var value: f32 = 0;
while (!ray.WindowShouldClose()) {
// Update
// Draw
ray.BeginDrawing();
defer ray.EndDrawing();
ray.ClearBackground(ray.RAYWHITE);
_ = ray.GuiSliderBar(rec, "StartAngle", null, &value, -450, 450);
ray.DrawFPS(10, 10);
}
The &value
parameter expects a pointer to a float variable that can be set to the value of the slider.
With that it worked.
It seems the cImport generates code that doesn’t work, I wonder whether there are more cases in other functions (that just aren’t used yet).
I don’t know whether there is a general solution to this, or if maybe raygui uses something that isn’t well supported by cImport.
It seems the sscanf
calls in GuiLoadStyle
don’t always get converted correctly.
Somehow becomes:
fileDataPtr += @as([*c]u8, @ptrFromInt(@sizeOf(c_int)));
I think it should just be:
fileDataPtr += @as(usize, @intCast(recsDataCompressedSize));
// and the next ones:
// fileDataPtr += @as([*c]u8, @ptrFromInt(@sizeOf(Rectangle)));
fileDataPtr += @as(usize, @sizeOf(Rectangle));
// fileDataPtr += @as([*c]u8, @ptrFromInt(@sizeOf(c_int)));
fileDataPtr += @as(usize, @sizeOf(c_int));
It seems cImport gets confused by the pointer arithmetic and instead wants to add a pointer to the pointer instead of adding an integer value to the pointer.
Edit:
I think the whole issue can be avoided by only applying translate-c to the cImported header file of raygui, but using a c source file for the implementation part. Raylib does this in its build.zig
: raylib/src/build.zig at 30f9ca7eb60d527e623066bbdc7257474da2baef · raysan5/raylib · GitHub
This uses raygui directly via the addRaylib
function provided by raylib: Adding raygui · Issue #5 · SimonLSchlee/zigraylib · GitHub and commit added raygui #5 · SimonLSchlee/zigraylib@60b2ed0 · GitHub