diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-25 12:11:02 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-25 12:27:49 -0300 |
| commit | 1803c4e7a8c0a6eb6360a7f602358c470b11dfbf (patch) | |
| tree | 854479cce605fe67f13396629ce7d7f0fe055c06 /dev | |
| parent | 58d7434f56a9fef3098cfc191fbd1cb32ec09cfb (diff) | |
| download | pardes-1803c4e7a8c0a6eb6360a7f602358c470b11dfbf.tar.gz pardes-1803c4e7a8c0a6eb6360a7f602358c470b11dfbf.zip | |
gui: a touchpad's fraction or a wheel's glide over a body whose TreeContext rows went no longer kills the window: emitScrollRows drew a body layer's rows past the grid's whenever the pane's slot kept a count of context rows (`context_rows != 0`), and a slot keeps that count, its width and its cells after its layer goes (draw.zig sets only `rows = 0` each frame; `rows == 0` is no layer, Layer.zig, as holdContext, renderFrame and the cover read it), so the first frame with a lag over a body whose context rows went (TreeContext turned off, or scrolled to where the top line has none) ran `for (bh..layer.rows)` with rows 0 under a body of bh rows and the range's length underflowed: `panic: integer overflow`, the session gone; the installed 9bd7dbb00a01 died so at 2026-11-25 11:58:30 (core dump: scroll_pane 1, scroll_lag +0.883, the glide at rest, the scroll's body 72 rows and 121 wide, the slot's layer rows 0 with context_rows 2, cols 121 and cells for 74 rows, its first rows the context rows it was last filled with; the pane's file at line 834 with tree_context false and context_rows 0: TreeContext had been on there and was off, then a touchpad scroll up; the trace's gui.zig:3706:49 is the one panic call ReleaseSafe merged the function's overflow checks into, a Debug build puts it on the range); THE FIX: the layer's rows are drawn from a layer the frame has (`rows != 0`), and scrollBody holds a scroll to its body layer's bounds: a layer shorter than the scroll's body (a pane shrunk under a glide, which keeps the rect it began on: the same underflow) or with fewer cells than its rows makes no scroll body, so that frame is drawn as it is, unmoved, where the loop panicked or read past the cells; TEST FIRST: gui.zig "a touchpad's fraction over a body whose context rows went (scrolled out of, TreeContext off) draws the rows the frame has: its body layer went with them" (quarter notches up from under two context rows to the file's top, then again after TreeContext off, each frame's instances counted: on the base `panic: integer overflow` at gui.zig:3708 `for (bh..layer.rows)`, each of the two ways alone) and "a scroll's body taller than its body layer (the pane shrunk under a glide) is drawn still, and nothing past a layer's cells is read" (on the base the same panic); GATES: unit-test -Dplatform=gui 1901/1905 (4 skipped), the one failed step the perf check's known BaselineHarnessMismatch; core-test 1083/1254 (171 skipped), as the base; a user hits it at the first touchpad scroll or wheel glide over a TreeContext body whose context rows went, every time, since d1cc6d5e3310 (2026-11-07); TreeContext is off by default, so the user met it once in that time
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/gui/gui.zig | 97 |
1 files changed, 96 insertions, 1 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index 9f6e4876..1d3fd926 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -3655,6 +3655,14 @@ fn scrollBody(g: *const Gui, surface: *const pardes.Surface) ?ScrollBody { }; const bw = sb.rect.w -| config.GUTTER; if (sb.lag == 0 or bw == 0 or sb.bh == 0 or sb.rect.x + config.GUTTER + bw > surface.cols or sb.y0 + sb.bh > surface.rows) return null; + // Its body layer, when the frame has one, under the whole body and a + // row of cells for each of its rows: a shorter one is a pane shrunk + // under the scroll (a glide keeps the rect it began on), and the frame + // is drawn as it is. + if (sb.pane < surface.body_layers.len) { + const layer = &surface.body_layers[sb.pane]; + if (layer.rows != 0 and (layer.rows < sb.bh or layer.cells.len < @as(usize, layer.rows) * layer.cols)) return null; + } return sb; } @@ -3703,7 +3711,10 @@ fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *cons // A body layer's held rows are compact, so it has rows past the grid's // (lifted into the body by what they save): the moving rows go on with // them, or the band under the grid's last row shows the layer's, still. - if (pane < surface.body_layers.len and surface.body_layers[pane].context_rows != 0) { + // A layer this frame has: one whose context rows went (scrolled out + // of, TreeContext off) is none (`rows == 0`), its slot keeping their + // count and its width. + if (pane < surface.body_layers.len and surface.body_layers[pane].rows != 0) { const layer = &surface.body_layers[pane]; if (layer.cols == bw) for (bh..layer.rows) |k| { const line = layer.cells[k * layer.cols ..][0..layer.cols]; @@ -7074,6 +7085,90 @@ test "a scroll's shifted rows start under the context rows, and its scissor belo try std.testing.expectEqual(@as(c_int, 20), scrollScissor(&g, layout).y); } +test "a touchpad's fraction over a body whose context rows went (scrolled out of, TreeContext off) draws the rows the frame has: its body layer went with them" { + const gpa = std.testing.allocator; + const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 24 }); + defer core.deinit(); + const pane = try core.setTestFile("pub const Box = struct {\n pub fn run() void {\n" ++ (std.mem.asBytes(&@as([30][16]u8, @splat(" // body\n".*)))) ++ " }\n};\n"); + gpa.free(pane.file.?.path); + pane.file.?.path = try gpa.dupe(u8, "/test.zig"); + if (!pardes.panes.File.supportsContext(pane)) return error.SkipZigTest; + core.update(.{ .resize = .{ .cols = 80, .rows = 24, .row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 6, .tagline_h = 12 } } }); + pane.file.?.tree_context = true; + core.sync(); + var wr = try WheelRun.init(gpa, core); + defer wr.deinit(gpa); + const id = core.view().active; + // The test's gui has no font: each frame is drawn with its cells, its + // layers' and the row that left blank. + const blank = try gpa.alloc(pardes.Cell, 2 * 80 * 24); + defer gpa.free(blank); + @memset(blank, .{}); + const instances = try gpa.alloc(CellInstance, 3 * 80 * 24); + defer gpa.free(instances); + // From line 5, under its two context rows, quarter notches up, a frame + // each, to the file's top: a row crossed leaves the picture three + // quarters of a row behind the core's. The frame that crosses onto + // `pub const Box` has no context rows; and with TreeContext turned off + // none has: no body layer, its last context rows and width still in + // its slot. + for ([_]bool{ false, true }) |off| { + pane.file.?.scroll = 4; + core.sync(); + core.needs_frame = true; + // The jump there glided to rest. + for (0..120) |_| try wr.frame(gpa, &.{}); + try std.testing.expect(!frontendMoving(&wr.g)); + try std.testing.expectEqual(@as(u16, 2), wr.g.frame.?.body_layers[id].context_rows); + try std.testing.expect(wr.g.frame.?.body_layers[id].rows != 0); + if (off) core.update(.{ .command = "TreeContext" }); + var gone: usize = 0; + for (0..20) |_| { + try wr.frame(gpa, &.{0.25}); + if (wr.g.scroll_lag == 0) continue; + var s = wr.g.frame.?.*; + s.cells = blank[0..s.cells.len]; + for (&s.body_layers) |*layer| layer.cells = blank[0..layer.cells.len]; + @memset(wr.g.scroll_edge, .{}); + const held = if (s.facts.pane(id)) |shown| shown.context_rows else 0; + const n = emitScrollRows(&wr.g, instances.ptr, 0, &s, fixedCellLayout(&wr.g), 800, 480, bg_default, held); + // The body's moving rows under the held ones, the layer's + // rows past the grid's while there is a layer, and the row + // that left. + const layer = &s.body_layers[id]; + const bw = wr.g.scroll_rect.w - config.GUTTER; + const past = if (layer.rows != 0) layer.rows - wr.g.scroll_body_h else 0; + try std.testing.expectEqual(@as(u32, wr.g.scroll_body_h - held + past + 1) * bw, n); + if (layer.rows == 0 and layer.context_rows != 0) gone += 1; + } + try std.testing.expect(gone > 0); + } +} + +test "a scroll's body taller than its body layer (the pane shrunk under a glide) is drawn still, and nothing past a layer's cells is read" { + var g = testGui(10, 20, 6, 12); + var grid: [40 * 20]pardes.Cell = @splat(.{}); + var short: [38 * 12]pardes.Cell = @splat(.{}); + var surface: pardes.Surface = .{ .cols = 40, .rows = 20, .cells = &grid }; + surface.body_layers[0] = .{ .viewport = .{ .x = 2, .y = 1, .w = 38, .h = 10 }, .cols = 38, .rows = 12, .context_rows = 2, .cells = &short }; + g.scroll_pane = 0; + g.scroll_lag = 0.5; + g.scroll_rect = .{ .x = 0, .y = 0, .w = 40, .h = 20 }; + g.scroll_body_y = 1; + g.scroll_body_h = 19; + var instances: [3 * 40 * 20]CellInstance = undefined; + const layout = fixedCellLayout(&g); + try std.testing.expectEqual(@as(u32, 0), emitScrollRows(&g, &instances, 0, &surface, layout, 400, 400, bg_default, 2)); + // As tall as the body, its cells short of its rows: the same. + surface.body_layers[0].rows = 21; + try std.testing.expectEqual(@as(u32, 0), emitScrollRows(&g, &instances, 0, &surface, layout, 400, 400, bg_default, 2)); + // Its cells all there: the body's moving rows under the two held, and + // the layer's two past the grid's. + var whole: [38 * 21]pardes.Cell = @splat(.{}); + surface.body_layers[0].cells = &whole; + try std.testing.expectEqual(@as(u32, (19 - 2 + 2) * 38), emitScrollRows(&g, &instances, 0, &surface, layout, 400, 400, bg_default, 2)); +} + test "concealed terminal text emits no ink on its ground" { var g = testGui(10, 20, 6, 12); var cell: pardes.Cell = .{ .default = false, .style = .{ .invisible = true, .ul = .single } }; |
