glfw: fix Monitor.getUserPointer alignment

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2021-07-17 17:18:12 -07:00
parent 9cac08b3b9
commit c5b89fef2e

View file

@ -180,7 +180,7 @@ pub inline fn getUserPointer(self: Monitor, comptime T: type) Error!?*T {
const ptr = c.glfwGetMonitorUserPointer(self.handle); const ptr = c.glfwGetMonitorUserPointer(self.handle);
try getError(); try getError();
if (ptr == null) return null; if (ptr == null) return null;
return @ptrCast(*T, @alignCast(@alignOf(*T), ptr.?)); return @ptrCast(*T, @alignCast(@alignOf(T), ptr.?));
} }
/// Returns the currently connected monitors. /// Returns the currently connected monitors.
@ -343,22 +343,21 @@ test "getName" {
} }
} }
// TODO(slimsag): panic: incorrect alignment. test "userPointer" {
// test "userPointer" { const glfw = @import("main.zig");
// const glfw = @import("main.zig"); try glfw.init();
// try glfw.init(); defer glfw.terminate();
// defer glfw.terminate();
// const monitor = try getPrimary(); const monitor = try getPrimary();
// if (monitor) |m| { if (monitor) |m| {
// var p = try m.getUserPointer(u32); var p = try m.getUserPointer(u32);
// try testing.expect(p == null); try testing.expect(p == null);
// var x: u32 = 5; var x: u32 = 5;
// try m.setUserPointer(u32, &x); try m.setUserPointer(u32, &x);
// p = try m.getUserPointer(u32); p = try m.getUserPointer(u32);
// try testing.expectEqual(p.?.*, 5); try testing.expectEqual(p.?.*, 5);
// } }
// } }
test "setCallback" { test "setCallback" {
const glfw = @import("main.zig"); const glfw = @import("main.zig");