diff --git a/lib/minifb/src/minifb.zig b/lib/minifb/src/minifb.zig index b0511d6..75fb0cc 100644 --- a/lib/minifb/src/minifb.zig +++ b/lib/minifb/src/minifb.zig @@ -78,7 +78,7 @@ pub fn Window(comptime TUserData: type) type { pub fn getUserData(self: Window(TUserData)) ?*TUserData { var cData = c.mfb_get_user_data(self.cwin); - return @ptrCast(?*TUserData, @alignCast(@alignOf(?*TUserData), cData)); + return @ptrCast(?*TUserData, @alignCast(@alignOf(TUserData), cData)); } pub const ActiveFunc = fn (win: Window(TUserData), isActive: bool) callconv(.C) void; @@ -102,6 +102,14 @@ test "user data is not null if previously set" { try testing.expectEqual(expected, win.getUserData().?.*); } +test "also works with smaller user data" { + const win = try Window(u8).open("abc", 100, 100, .{}); + var data: u8 = 42; + win.setUserData(&data); + const expected: u8 = 42; + try testing.expectEqual(expected, win.getUserData().?.*); +} + pub fn getTargetFPS() u32 { return c.mfb_get_target_fps(); }