diff --git a/glfw/src/key.zig b/glfw/src/key.zig index 45038671..fd49b463 100644 --- a/glfw/src/key.zig +++ b/glfw/src/key.zig @@ -20,6 +20,8 @@ const cc = @import("c.zig").c; const Error = @import("errors.zig").Error; const getError = @import("errors.zig").getError; +const internal_debug = @import("internal_debug.zig"); + /// enum containing all glfw keys pub const Key = enum(c_int) { /// The unknown key @@ -212,9 +214,13 @@ pub const Key = enum(c_int) { /// @thread_safety This function must only be called from the main thread. /// /// see also: input_key_name - pub inline fn getName(self: Key, scancode: isize) Error!?[:0]const u8 { + pub inline fn getName(self: Key, scancode: isize) error{ PlatformError }!?[:0]const u8 { + internal_debug.assertInitialized(); const name_opt = cc.glfwGetKeyName(@enumToInt(self), @intCast(c_int, scancode)); - try getError(); + getError() catch |err| return switch (err) { + Error.PlatformError => err, + else => unreachable, + }; return if (name_opt) |name| std.mem.span(name) else @@ -233,9 +239,14 @@ pub const Key = enum(c_int) { /// Possible errors include glfw.Error.NotInitialized, glfw.Error.InvalidEnum and glfw.Error.PlatformError. /// /// @thread_safety This function may be called from any thread. - pub inline fn getScancode(self: Key) Error!isize { + pub inline fn getScancode(self: Key) error{ PlatformError }!isize { + internal_debug.assertInitialized(); const scancode = cc.glfwGetKeyScancode(@enumToInt(self)); - try getError(); + getError() catch |err| return switch (err) { + Error.InvalidEnum => unreachable, // Should be unreachable for any valid 'Key' value. + Error.PlatformError => err, + else => unreachable, + }; return scancode; } };