diff --git a/glfw/src/clipboard.zig b/glfw/src/clipboard.zig index bc4fe6bd..985ad463 100644 --- a/glfw/src/clipboard.zig +++ b/glfw/src/clipboard.zig @@ -4,6 +4,8 @@ const c = @import("c.zig").c; const Error = @import("errors.zig").Error; const getError = @import("errors.zig").getError; +const internal_debug = @import("internal_debug.zig"); + /// Sets the clipboard to the specified string. /// /// This function sets the system clipboard to the specified, UTF-8 encoded string. @@ -17,9 +19,13 @@ const getError = @import("errors.zig").getError; /// @thread_safety This function must only be called from the main thread. /// /// see also: clipboard, glfwGetClipboardString -pub inline fn setClipboardString(value: [*:0]const u8) Error!void { +pub inline fn setClipboardString(value: [*:0]const u8) error{ PlatformError }!void { + internal_debug.assertInitialized(); c.glfwSetClipboardString(null, value); - try getError(); + getError() catch |err| return switch (err) { + Error.PlatformError => err, + else => unreachable, + }; } /// Returns the contents of the clipboard as a string. @@ -39,9 +45,13 @@ pub inline fn setClipboardString(value: [*:0]const u8) Error!void { /// @thread_safety This function must only be called from the main thread. /// /// see also: clipboard, glfwSetClipboardString -pub inline fn getClipboardString() Error![:0]const u8 { +pub inline fn getClipboardString() error{ PlatformError }![:0]const u8 { + internal_debug.assertInitialized(); const value = c.glfwGetClipboardString(null); - try getError(); + getError() catch |err| return switch (err) { + Error.PlatformError => err, + else => unreachable, + }; return std.mem.span(value); } diff --git a/glfw/src/internal_debug.zig b/glfw/src/internal_debug.zig index 74a085e6..0899a90f 100644 --- a/glfw/src/internal_debug.zig +++ b/glfw/src/internal_debug.zig @@ -1,6 +1,8 @@ const std = @import("std"); const zig_builtin = @import("builtin"); +// TODO: Consider if this idea could also be applied to prevent 'PlatformError' + const debug_mode = (zig_builtin.mode == .Debug); var glfw_initialized = if (debug_mode) false else @as(void, {}); pub inline fn toggleInitialized() void {