diff --git a/src/main.zig b/src/main.zig index 3a2f64c..8d69191 100644 --- a/src/main.zig +++ b/src/main.zig @@ -107,7 +107,7 @@ pub fn main() !void { var buf: [8]u8 = undefined; const timer_ms = timer.getTicks(); // const timer_base = std.math.log10(timer_ms) + 3; - const time_str: []const u8 = try std.fmt.bufPrint(&buf, "{d}ms", .{timer_ms}); + const time_str: [*:0]const u8 = try std.fmt.bufPrintZ(&buf, "{d}ms", .{timer_ms}); var time_text = try GameText.loadFromRenderedText(time_str, RGBAColor.whiteSmoke().tosdl()); try time_text.render( &game_state, diff --git a/src/text.zig b/src/text.zig index 29d0aa9..60b8714 100644 --- a/src/text.zig +++ b/src/text.zig @@ -9,15 +9,14 @@ var text_texture: ?*sdl.SDL_Texture = null; var text_init = false; pub const GameText = struct { - text: []const u8, + text: [*:0]const u8, color: sdl.SDL_Color, surface: *sdl.SDL_Surface, w: u32, h: u32, - pub fn loadFromRenderedText(text: []const u8, color: sdl.SDL_Color) !GameText { - const trunc_str = text[0..text.len]; - const c_text: [*c]const u8 = @ptrCast(trunc_str); + pub fn loadFromRenderedText(text: [*:0]const u8, color: sdl.SDL_Color) !GameText { + const c_text: [*c]const u8 = @ptrCast(text); const text_surface: [*c]sdl.SDL_Surface = sdl.TTF_RenderText_Solid(font.?, c_text, color) orelse { sdl.SDL_Log("Error loading text surface: %s\n", sdl.SDL_GetError()); return error.FailedToRenderSurface;