From 6f2f7056b75d08bd19dc397ccfe7b904619ca51a Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 31 Jul 2022 11:03:48 -0700 Subject: [PATCH] gpu: make Device.setUncapturedErrorCallback friendlier Signed-off-by: Stephen Gutekanst --- gpu/src/device.zig | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gpu/src/device.zig b/gpu/src/device.zig index b64eb3fc..ce270d03 100644 --- a/gpu/src/device.zig +++ b/gpu/src/device.zig @@ -194,10 +194,16 @@ pub const Device = opaque { // TODO: presumably callback should be nullable for unsetting pub inline fn setUncapturedErrorCallback( device: *Device, - callback: ErrorCallback, - userdata: ?*anyopaque, + comptime Context: type, + comptime callback: fn (typ: ErrorType, message: [*:0]const u8, ctx: Context) callconv(.Inline) void, + context: Context, ) void { - Impl.deviceSetUncapturedErrorCallback(device, callback, userdata); + const Helper = struct { + pub fn callback(typ: ErrorType, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { + callback(typ, message, if (Context == void) {} orelse @ptrCast(Context, userdata)); + } + }; + Impl.deviceSetUncapturedErrorCallback(device, Helper.callback, if (Context == void) null orelse context); } pub inline fn tick(device: *Device) void {