diff --git a/lib/preludes/raylib-prelude.zig b/lib/preludes/raylib-prelude.zig index b23aca9..28ac8ee 100755 --- a/lib/preludes/raylib-prelude.zig +++ b/lib/preludes/raylib-prelude.zig @@ -17,7 +17,7 @@ pub const RaylibError = error{ LoadFontData, LoadCodepoints, LoadMaterials, - LoadModelAnimations + LoadModelAnimations, }; pub const Vector2 = extern struct { @@ -1292,7 +1292,7 @@ pub const Font = extern struct { } /// Load font from memory buffer, fileType refers to extension: i.e. '.ttf' - pub fn fromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font { + pub fn fromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: ?[]i32) Font { return rl.loadFontFromMemory(fileType, fileData, fontSize, fontChars); } @@ -2107,14 +2107,15 @@ pub fn loadFontEx(fileName: [*:0]const u8, fontSize: i32, fontChars: ?[]i32) Fon } /// Load font from memory buffer, fileType refers to extension: i.e. '.ttf' -pub fn loadFontFromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font { +pub fn loadFontFromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: ?[]i32) Font { var fileDataFinal = @as([*c]const u8, 0); var fileDataLen: i32 = 0; if (fileData) |fileDataSure| { fileDataFinal = @as([*c]const u8, @ptrCast(fileDataSure)); fileDataLen = @as(i32, @intCast(fileDataSure.len)); } - return cdef.LoadFontFromMemory(@as([*c]const u8, @ptrCast(fileType)), @as([*c]const u8, @ptrCast(fileDataFinal)), @as(c_int, @intCast(fileDataLen)), @as(c_int, fontSize), @as([*c]c_int, @ptrCast(fontChars)), @as(c_int, @intCast(fontChars.len))); + const codepointCount: c_int = if (fontChars) |fontCharsSure| @intCast(fontCharsSure.len) else 0; + return cdef.LoadFontFromMemory(@as([*c]const u8, @ptrCast(fileType)), @as([*c]const u8, @ptrCast(fileDataFinal)), @as(c_int, @intCast(fileDataLen)), @as(c_int, fontSize), @as([*c]c_int, @ptrCast(fontChars)), codepointCount); } /// Load font data for further use diff --git a/lib/raylib.zig b/lib/raylib.zig index 8adc8c0..ca733e1 100644 --- a/lib/raylib.zig +++ b/lib/raylib.zig @@ -17,7 +17,7 @@ pub const RaylibError = error{ LoadFontData, LoadCodepoints, LoadMaterials, - LoadModelAnimations + LoadModelAnimations, }; pub const Vector2 = extern struct { @@ -1292,7 +1292,7 @@ pub const Font = extern struct { } /// Load font from memory buffer, fileType refers to extension: i.e. '.ttf' - pub fn fromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font { + pub fn fromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: ?[]i32) Font { return rl.loadFontFromMemory(fileType, fileData, fontSize, fontChars); } @@ -2107,14 +2107,15 @@ pub fn loadFontEx(fileName: [*:0]const u8, fontSize: i32, fontChars: ?[]i32) Fon } /// Load font from memory buffer, fileType refers to extension: i.e. '.ttf' -pub fn loadFontFromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: []i32) Font { +pub fn loadFontFromMemory(fileType: [*:0]const u8, fileData: ?[]const u8, fontSize: i32, fontChars: ?[]i32) Font { var fileDataFinal = @as([*c]const u8, 0); var fileDataLen: i32 = 0; if (fileData) |fileDataSure| { fileDataFinal = @as([*c]const u8, @ptrCast(fileDataSure)); fileDataLen = @as(i32, @intCast(fileDataSure.len)); } - return cdef.LoadFontFromMemory(@as([*c]const u8, @ptrCast(fileType)), @as([*c]const u8, @ptrCast(fileDataFinal)), @as(c_int, @intCast(fileDataLen)), @as(c_int, fontSize), @as([*c]c_int, @ptrCast(fontChars)), @as(c_int, @intCast(fontChars.len))); + const codepointCount: c_int = if (fontChars) |fontCharsSure| @intCast(fontCharsSure.len) else 0; + return cdef.LoadFontFromMemory(@as([*c]const u8, @ptrCast(fileType)), @as([*c]const u8, @ptrCast(fileDataFinal)), @as(c_int, @intCast(fileDataLen)), @as(c_int, fontSize), @as([*c]c_int, @ptrCast(fontChars)), codepointCount); } /// Load font data for further use