From 8bad8e3701716a5f2d82d8255a39f3743b13fb96 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 18:19:13 -0300 Subject: views: a pane's slot for the view live when it is made is written too, and emptied when its view goes live, so a pane closed before that view parks again frees no selections that are not its slot's installed() wrote the slots of the views not live and marked every open view's known, the live one's left as it was; and unpark() left a view's slot holding the selections it had just given the live body. A pane made, then closed while its view was still live and torn down after another went live (a Zerox twin closed at once, say) freed that view's slot: whatever the slot held, or the live body's selections a second time. A view's slot is now made fresh for the live view as for the others, and holds no selections while its view is live. Found by test/replicas.zig, whose replicas switch views on every input; the views unit tests and snapshots (views, views-pan, views-term) pass as they did. Co-Authored-By: Claude Opus 5.5 --- src/views.zig | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/views.zig b/src/views.zig index c847b987..e99e1694 100644 --- a/src/views.zig +++ b/src/views.zig @@ -165,7 +165,10 @@ fn fresh(pane: *const Pane) PaneView { pub fn installed(p: *Pardes, pane: *Pane) void { pane.sized_by = p.view; if (!several(p)) return; - for (0..max) |k| if (k != p.view and isOpen(p, @intCast(k))) { + // The live view's slot too, owning nothing: a pane closed before its + // view next parks is torn down with that slot never written, and + // `tornDown` frees what the slots of the views not live hold. + for (0..max) |k| if (isOpen(p, @intCast(k))) { pane.pv[k] = fresh(pane); }; pane.pv_known = p.views_open; @@ -197,7 +200,14 @@ fn unpark(p: *Pardes, k: u8) void { const slot = p.parked[k].?; copy(&fields, p, &slot.view); p.view = k; - for (p.panes) |s| if (s) |pane| apply(pane, &pane.pv[k]); + for (p.panes) |s| if (s) |pane| { + apply(pane, &pane.pv[k]); + // The live body owns the selections now; the slot, stale while its + // view is live, holds none (a pane closed before the view parks + // again would otherwise free them twice). + pane.pv[k].body.sels = &.{}; + pane.pv[k].body.nsel = 0; + }; // The panes closed while it was out (a slot empty or another pane's // now) leave its layout, and its keyboard leaves them. for (0..p.ncol) |c| { -- cgit v1.3