Skip to content

Commit

Permalink
fix user event wrapping error
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Ji committed Nov 19, 2024
1 parent 0f190d7 commit 3c70c63
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/io.zig
Original file line number Diff line number Diff line change
Expand Up @@ -593,17 +593,21 @@ pub const Event = union(enum) {
sdl.SDL_SENSORUPDATE => Event{ .sensor_update = raw.sensor },
sdl.SDL_RENDER_TARGETS_RESET => Event{ .render_targets_reset = raw.common },
sdl.SDL_RENDER_DEVICE_RESET => Event{ .render_device_reset = raw.common },
sdl.SDL_USEREVENT => Event{ .user = UserEvent.from(raw.user) },
else => @panic("Unsupported event type detected!"),
else => |t| if (t >= sdl.SDL_USEREVENT and t <= last_user_event_type)
Event{ .user = UserEvent.from(raw.user) }
else
@panic("Unsupported event type detected!"),
};
}
};

/// register `num` user events and return the corresponding type
/// to be used when generating those.
var last_user_event_type: u32 = undefined;
pub fn registerEvents(num: i32) !u32 {
const res = sdl.SDL_RegisterEvents(num);
if (res == std.math.maxInt(u32)) return error.CannotRegisterUserEvent;
last_user_event_type = res + num - 1;
return res;
}

Expand Down

0 comments on commit 3c70c63

Please sign in to comment.