From cb4f911782428460d7f4d732b2a41f92d9a2dfde Mon Sep 17 00:00:00 2001 From: InKryption <59504965+InKryption@users.noreply.github.com> Date: Mon, 29 Nov 2021 19:41:48 +0000 Subject: [PATCH] glfw: Fix pointer cast The GLFW implementation takes a constant pointer to a `VkAllocationCallbacks` struct; casting it to a mutable pointer equivalent here doesn't break anything, but does prevent passing a valid const pointer, which is often what one should prefer to do. As well, the `@alignOf` builtin takes the alignment expected of the type directly, so `@alignOf(*T)` returns the alignment of `*T`, not `T`, so that has also been corrected. --- glfw/src/vulkan.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glfw/src/vulkan.zig b/glfw/src/vulkan.zig index d7d41668..e29a4efa 100644 --- a/glfw/src/vulkan.zig +++ b/glfw/src/vulkan.zig @@ -215,8 +215,8 @@ pub inline fn createWindowSurface(vk_instance: anytype, window: Window, vk_alloc const v = c.glfwCreateWindowSurface( instance, window.handle, - if (vk_allocation_callbacks == null) null else @ptrCast(*c.VkAllocationCallbacks, @alignCast(@alignOf(*c.VkAllocationCallbacks), vk_allocation_callbacks)), - @ptrCast(*c.VkSurfaceKHR, @alignCast(@alignOf(*c.VkSurfaceKHR), vk_surface_khr)), + if (vk_allocation_callbacks == null) null else @ptrCast(*const c.VkAllocationCallbacks, @alignCast(@alignOf(c.VkAllocationCallbacks), vk_allocation_callbacks)), + @ptrCast(*c.VkSurfaceKHR, @alignCast(@alignOf(c.VkSurfaceKHR), vk_surface_khr)), ); getError() catch |err| return switch (err) { Error.InvalidValue => @panic("Attempted to use window with client api to create vulkan surface."),