From bf47ecd04e33b4c392e8c015db5f12b79c4401ee Mon Sep 17 00:00:00 2001 From: Sho Sakakibara Date: Wed, 31 Dec 2025 13:34:36 +0900 Subject: [PATCH] fix: clamp negative mouse coordinates to prevent @intCast panic Mouse coordinates can be negative when cursor moves off-screen during rapid movement. Since vxfw.Point uses u16, the @intCast panics on negative i16 values. --- src/vxfw/App.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vxfw/App.zig b/src/vxfw/App.zig index c8088a7e..3b1f0b25 100644 --- a/src/vxfw/App.zig +++ b/src/vxfw/App.zig @@ -350,8 +350,8 @@ const MouseHandler = struct { .z_index = 0, }; const mouse_point: vxfw.Point = .{ - .row = @intCast(mouse.row), - .col = @intCast(mouse.col), + .row = if (mouse.row < 0) 0 else @intCast(mouse.row), + .col = if (mouse.col < 0) 0 else @intCast(mouse.col), }; if (sub.containsPoint(mouse_point)) { try last_frame.hitTest(app.allocator, &hits, mouse_point); @@ -409,8 +409,8 @@ const MouseHandler = struct { .z_index = 0, }; const mouse_point: vxfw.Point = .{ - .row = @intCast(mouse.row), - .col = @intCast(mouse.col), + .row = if (mouse.row < 0) 0 else @intCast(mouse.row), + .col = if (mouse.col < 0) 0 else @intCast(mouse.col), }; if (sub.containsPoint(mouse_point)) { try last_frame.hitTest(app.allocator, &hits, mouse_point);