From 4c72f7b02fbafd15d0cf843edece106714bcc5f7 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Thu, 15 Oct 2026 12:38:32 +0300 Subject: Keep the snapshot unchanged when an update fails term_snapshot_update converted the viewport in place, so an allocation that failed midway left the snapshot empty and a renderer painted a blank frame. Split the update into two phases. Phase 1 makes every allocation the update needs and counts the arena words the converted rows add, then grows the arena once. Phase 2 writes the view, cells, keys, clusters, and selection, and cannot fail. A failed update now keeps the previous content, and a retry is an ordinary incremental update. invalidate() is removed. The term_snapshot_update comment and the correctness audit now say the snapshot keeps its previous content. The failure test fails each allocation in turn from the same starting state. After every failed call it compares the view, cells, row keys, selection spans, and cluster code points with the state before the call. A retry must succeed and match a fresh capture. The cases are a first update, a 32 by 16 screen of ZWJ families and regional-indicator flags (arena growth), a resize, a 300-row screen (scratch arrays), and a long scroll run. Co-Authored-By: Claude Haiku 5.5 --- include/term/term.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/term/term.h b/include/term/term.h index dc41114..2447b72 100644 --- a/include/term/term.h +++ b/include/term/term.h @@ -382,7 +382,7 @@ TERM_API void term_snapshot_free(struct term_snapshot *s); /* Copy the viewport of t into s. Keep rows with unchanged content keys. * Update the history view index and refine counts for visible wide lines. - * Return false when memory runs out. The snapshot is then empty. */ + * Return false when memory runs out. The snapshot then keeps its previous content. */ TERM_API bool term_snapshot_update(struct term_snapshot *s, struct term *t); /* Palette entries of struct term_view.palette after the 256 indexed colors. */ -- cgit v1.2.3