From dec1f08dd18f0e04f1795cec19c8393a0842adfc Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 31 Jul 2022 13:43:17 -0700 Subject: [PATCH] gpu: make Device.popErrorScope 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 b73add5d..1565e646 100644 --- a/gpu/src/device.zig +++ b/gpu/src/device.zig @@ -203,10 +203,16 @@ pub const Device = opaque { pub inline fn popErrorScope( 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, ) bool { - return Impl.devicePopErrorScope(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) {} else @ptrCast(Context, userdata)); + } + }; + return Impl.devicePopErrorScope(device, Helper.callback, if (Context == void) null else context); } pub inline fn pushErrorScope(device: *Device, filter: ErrorFilter) void {