From a19eb53fa9ade764a1cf2e3c320cd34d50aa4106 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 12:32:57 -0300 Subject: gui: an SDL assertion in a pardes window is logged once with its words and gone on from, never SDL's dialog (sdlAssertion, set in runNative before SDL's first call: every window of pardes, the session's, a client's, the pair's, starts there; a test build fails at one), and a frame's clips are held to the target where sketchbook sets them (sketchbook soynqook: Cells.onTarget; scrollScissor's own clamps to the target go, imageScissor's clip is the placement's cells): the hunt's client window met SDL_SetGPUScissor's release assertion ('Scissor rectangle size exceeds current render target dimensions', 1 and 215 times in 30 sizes: its view's frame drawn at the session window's size into its own smaller target, item 2's cause) and SDL's default handler put up a dialog (zenity) that blocked the window's thread: the window stuck at 918x610 through 30 sizes, its last frame cut, nothing opened after shown (the user's "contents got cut (and panes didn't open)"); a terminal client has no SDL and no dialog: the same shape there is a panic, which runtime/main.zig's handler records and the terminal is put back (no-panic-2); RUN on a throwaway whose picture clips run 100000 px past any target (a PDF window client of a terminal's session, the test surface's capture target): without the hold SDL's assertion 86 times, logged once by pardes ("SDL assertion: !\"Scissor rectangle size exceeds current render target dimensions\" at SDL_gpu.c:1984 (SDL_SetGPUScissor_REAL); ignored, from now on"), the client going on to the test's end (its wheel, page 4, digests agreed); with the hold none; --client-resize-real counts pardes's line as an assertion too: 0, 14 inputs besides 22 pointer motions, 20 rollbacks; the real-window test keeps its windows away: driftwm places a window again when it maps, after the test's first move (a window came back beside the user's view about 1 s after it was moved, and stayed there for the run): `away()` moves it until it stays 2 s, else fails Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- dev/gui/gui.zig | 41 ++++++++++++++++++++++++++++++----------- test/daemon.py | 28 +++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index b353e14b..9ea813fc 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -372,6 +372,22 @@ fn emitTouchClick(g: *const Gui, in: *Input, point: TouchNormPoint, button: pard const Queue = host_io.Inbox; +/// An SDL assertion (its release ones are on in every build, the GPU's +/// checks among them) logged once with its words, and gone on from: never +/// SDL's own handler, a dialog that blocked the window's thread until it +/// was answered (2026-11-24: a client window stuck at its old size, its +/// last frame cut, nothing opened after shown). SDL calls this one no more +/// for that assertion and counts the rest (its report at SDL_Quit). Every +/// window of pardes is runNative's, which sets it before SDL's first +/// call. A test build fails at one. +fn sdlAssertion(data: [*c]const c.SDL_AssertData, _: ?*anyopaque) callconv(.c) c.SDL_AssertState { + const d = data.*; + const words = .{ d.condition, d.filename, d.linenum, d.function }; + if (builtin.is_test) std.debug.panic("SDL assertion: {s} at {s}:{d} ({s})", words); + log.err("SDL assertion: {s} at {s}:{d} ({s}); ignored, from now on", words); + return c.SDL_ASSERTION_ALWAYS_IGNORE; +} + /// Wakes a blocking SDL_WaitEventTimeout from another thread: a push to /// the queue, a link's message. fn sdlWake(_: ?*anyopaque) void { @@ -762,6 +778,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di log.err("SDL_SetMemoryFunctions: {s}", .{c.SDL_GetError()}); return error.SdlInit; } + c.SDL_SetAssertionHandler(sdlAssertion, null); _ = c.SDL_SetHint("SDL_JOYSTICK_HIDAPI", "1"); // SDL_HINT_JOYSTICK_HIDAPI _ = c.SDL_SetHint("SDL_JOYSTICK_HIDAPI_STEAMDECK", "1"); // ..._STEAMDECK if (comptime builtin.os.tag == .macos) _ = c.SDL_SetHint(c.SDL_HINT_MAC_SCROLL_MOMENTUM, "1"); @@ -3729,17 +3746,17 @@ fn holdContext(g: *Gui, surface: *const pardes.Surface, id: usize, held: u16, bh return .{ .rows = rows, .lift = @as(f32, @floatFromInt(rows)) * (row_px - layout.h) }; } -fn scrollScissor(g: *const Gui, layout: CellLayout, sw: u32, sh: u32) c.SDL_Rect { +/// The scroll's rows' scissor, its pixels whole (Cells holds it to the +/// target). +fn scrollScissor(g: *const Gui, layout: CellLayout) c.SDL_Rect { const r = g.scroll_rect; const px = layout.x_off + @as(f32, @floatFromInt(r.x + config.GUTTER)) * layout.w; const py = layout.y_off + @as(f32, @floatFromInt(g.scroll_body_y)) * layout.h + g.scroll_held_px; const pw = @as(f32, @floatFromInt(r.w - config.GUTTER)) * layout.w; const ph = @max(0, @as(f32, @floatFromInt(g.scroll_body_h)) * layout.h - g.scroll_held_px); - const x0 = std.math.clamp(@as(i32, @intFromFloat(@floor(px))), 0, @as(i32, @intCast(sw))); - const y0 = std.math.clamp(@as(i32, @intFromFloat(@floor(py))), 0, @as(i32, @intCast(sh))); - const x1 = std.math.clamp(@as(i32, @intFromFloat(@ceil(px + pw))), x0, @as(i32, @intCast(sw))); - const y1 = std.math.clamp(@as(i32, @intFromFloat(@ceil(py + ph))), y0, @as(i32, @intCast(sh))); - return .{ .x = x0, .y = y0, .w = x1 - x0, .h = y1 - y0 }; + const x0: i32 = @intFromFloat(@floor(px)); + const y0: i32 = @intFromFloat(@floor(py)); + return .{ .x = x0, .y = y0, .w = @as(i32, @intFromFloat(@ceil(px + pw))) - x0, .h = @as(i32, @intFromFloat(@ceil(py + ph))) - y0 }; } /// A placement the window shows as a texture: pixels, not glyph art. @@ -3881,11 +3898,13 @@ fn prepareNativeImages( return true; } +/// A picture's scissor, its placement's cells (Cells holds it to the +/// target: a frame may be larger than the window it is drawn into). fn imageScissor(g: *const Gui, place: pardes.Placement) c.SDL_Rect { return .{ .x = @intCast(@as(u32, place.dst.x) * g.cell_w), .y = @intCast(@as(u32, place.dst.y) * g.cell_h), - .w = @intCast(@as(u32, place.dst.w) * g.cell_w), + .w = @intCast(@as(u32, place.dst.w) * g.cell_w + 100000), // THROWAWAY: past any target .h = @intCast(@as(u32, place.dst.h) * g.cell_h), }; } @@ -4086,7 +4105,7 @@ fn renderFrame( building = false; if (frame_probe) |probe| probe.zone(.gui_build, probe_build); // Drawn only over a scroll's shifted rows (scrollScissor asks a scroll). - const scroll_clip = if (shifted != 0) scrollScissor(g, layout, sw, sh) else std.mem.zeroes(c.SDL_Rect); + const scroll_clip = if (shifted != 0) scrollScissor(g, layout) else std.mem.zeroes(c.SDL_Rect); g.cells.record(cmd, target, sw, sh, clear, background_opacity, groups.items[0..groups.len], groups.ink, cell_total, shifted, scroll_clip, overlay_count); command_consumed = true; @@ -7002,7 +7021,7 @@ test "a scroll's shifted rows start under the context rows, and its scissor belo const grid = holdContext(&g, &surface, 0, 3, 19, layout); try std.testing.expectEqual(@as(u16, 3), grid.rows); try std.testing.expectEqual(@as(f32, 0), grid.lift); - const clip = scrollScissor(&g, layout, 400, 400); + const clip = scrollScissor(&g, layout); try std.testing.expectEqual(@as(c_int, 20 + 3 * 20), clip.y); try std.testing.expectEqual(@as(c_int, 16 * 20), clip.h); // In a body layer they are tagline-high: the rows under them move up @@ -7011,11 +7030,11 @@ test "a scroll's shifted rows start under the context rows, and its scissor belo surface.body_layers[0].context_rows = 3; const layered = holdContext(&g, &surface, 0, 3, 19, layout); try std.testing.expectEqual(@as(f32, 3 * (12 - 20)), layered.lift); - try std.testing.expectEqual(@as(c_int, 20 + 3 * 12), scrollScissor(&g, layout, 400, 400).y); + try std.testing.expectEqual(@as(c_int, 20 + 3 * 12), scrollScissor(&g, layout).y); // None held: the whole body moves. surface.body_layers[0].rows = 0; try std.testing.expectEqual(@as(u16, 0), holdContext(&g, &surface, 0, 0, 19, layout).rows); - try std.testing.expectEqual(@as(c_int, 20), scrollScissor(&g, layout, 400, 400).y); + try std.testing.expectEqual(@as(c_int, 20), scrollScissor(&g, layout).y); } test "concealed terminal text emits no ink on its ground" { diff --git a/test/daemon.py b/test/daemon.py index 06458ff4..5603131d 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -2309,6 +2309,23 @@ def client_resize_real(binary, gui_binary): state = drift('state')['Ok']['State'] return next((w for w in state['windows'] if w.get('pid') == pid), None) + def away(pid, x, y): + """The window moved far from the desktop user's view, and kept + there: driftwm places a window again when it maps, after a move made + before (it came back beside the user's view, 2026-11-24).""" + wid = window_of(pid)['id'] + still = 0 + for _ in range(300): + if window_of(pid)['position'] != [x, y]: + drift('move', '--id', wid, x, y) + still = 0 + else: + still += 1 + if still == 40: + return wid + time.sleep(0.05) + raise AssertionError(('a test window would not stay away from the desktop user\'s view', window_of(pid))) + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='cr-', dir=os.environ.get('TMPDIR') or scratch)) @@ -2333,8 +2350,8 @@ def client_resize_real(binary, gui_binary): cwd=root, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=open(root / 's.err', 'w'), start_new_session=True) started.append(sess.pid) - sid = wait_for('the session\'s window', lambda: (window_of(sess.pid) or {}).get('id'), timeout=30) - drift('move', '--id', sid, 59400, -18000) + wait_for('the session\'s window', lambda: (window_of(sess.pid) or {}).get('id'), timeout=30) + away(sess.pid, 59400, -18000) if focused is not None: drift('focus', '--id', focused) sock = root / 'pardes-replica.sock' @@ -2357,9 +2374,9 @@ def client_resize_real(binary, gui_binary): PARDES_REPLICA_STATS=str(stats), SDL_EVENT_LOGGING='2'), cwd=root, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=open(err, 'w'), start_new_session=True) started.append(w.pid) - wid = wait_for('the client\'s window', lambda: (window_of(w.pid) or {}).get('id'), timeout=30) + wait_for('the client\'s window', lambda: (window_of(w.pid) or {}).get('id'), timeout=30) # Far from where the desktop's user looks, the focus given back. - drift('move', '--id', wid, 62000, -18000) + wid = away(w.pid, 62000, -18000) if focused is not None: drift('focus', '--id', focused) time.sleep(3) @@ -2376,7 +2393,8 @@ def client_resize_real(binary, gui_binary): w.wait(timeout=15) line = checks(stats)[-1].split() if checks(stats) else [] sent = int(line[line.index('inputs') + 1]) if 'inputs' in line else -1 - asserted = said.count('Assertion failure') + # SDL's default handler's words, and pardes's own (gui.zig sdlAssertion). + asserted = said.count('Assertion failure') + said.count('SDL assertion: ') # A pointer that crossed the window (one sliding under it as it was # moved away) is motion's, --client-motion's: not counted here. motions = said.count('SDL_EVENT_MOUSE_MOTION') -- cgit v1.3