szn

Bug 493 — eraseDisplay leaves stale sixel marker cells

493. Image freed, markers left behind pointing at a dead id

Severity: MEDIUM (stale markers; dead-id dereference surface) Status: 🟢 FIXED Files: src/screen.zig:1195-1215

Problem

For ED 0 an image is removed when (anchor_row + cell_rows) > cursor.y; for ED 1 when anchor_row <= cursor.y. A straddling image — anchored on one side of the erased region, extending into it — is freed (img_ptr.deinit), its slot nulled, and its refcount zeroed. But the marker cells on the non-erased side keep attr.sixel = true with the now-dead image id.

Downstream code treats attr.sixel markers as live references (refcounting, re-render lookups via findSixelImage, erase paths). A dead id there is at best a rendering glitch (markers with no image) and at worst a slot-reuse aliasing bug if the slot is recycled for a new image while stale markers still point at it.

Proposed Fix

Either clear the surviving marker cells when removing a straddling image, or don’t remove images that extend outside the erased region (only remove fully-contained ones). The removal predicate and the marker cleanup must agree on the same region.

Resolution

Added clearSixelMarkerCells(self: *Screen, image_id: u32) which scans grid lines and resets any cells pointing to image_id to eraseCell(). Called this in eraseDisplay whenever an image is removed/evicted so that straddling images never leave behind stale marker cells pointing to dead image IDs. Added regression tests eraseDisplay 0 clears surviving marker cells of straddling sixel image — bug #493 and eraseDisplay 1 clears surviving marker cells of straddling sixel image — bug #493.