Closed clebs closed 5 months ago
It seems as if the slice continues to be iterated despite hitting the sentinel.
The fix is this:
- b[0.. :0]
+ b[0 .. b.len-1 :0]
:0
asserts that after the end of the slice a sentinel is present, which is not given in your case.
A way better solution is this:
var b = std.mem.zeroes([8]u8);
const string = try std.fmt.bufPrintZ(b[0..], "{s}", .{"Hello"});
const text = try sdl.createTextureFromSurface(renderer, try font.renderTextSolid(string, sdl.Color.white));
Hi,
Thanks for the solution! If I understand correctly :0
means I need a slice that has 0s after the end, not a slice which contains 0s in its last position(s).
Therefore I always have to provide a subslice of my array, guaranteeing that after subslice.len there is a 0.
I guess then this was working by accident in previous zig builds....
Thanks for the solution! If I understand correctly :0 means I need a slice that has 0s after the end, not a slice which contains 0s in its last position(s).
Exactly!
Hi there! I have just updated to the latest version after a couple of months pause working on a small game.
To render text I am using
sdl.ttf.renderTextSolid()
and after updating to zig 0.12 and latest SDL.zig it panics despite the slice passed being 0 terminated. It used to work a couple of months ago (I unfortunately do not know the exact commit to bisect...).I have created a minimal example to reproduce this:
Running this code I get the following output:
It seems as if the slice continues to be iterated despite hitting the sentinel. I tried debugging this but was not able to follow out of the C ABI boundary.
With some guidance I would gladly help fix it 🙂