]> git.eshelyaron.com Git - emacs.git/commitdiff
TTY menus: handle saved state referencing dead frames
authorGerd Möllmann <gerd@gnu.org>
Tue, 5 Nov 2024 09:26:36 +0000 (10:26 +0100)
committerEshel Yaron <me@eshelyaron.com>
Mon, 23 Dec 2024 14:54:03 +0000 (15:54 +0100)
* src/term.c (restore_desired_matrix): If a tty menu saves a current
matrix that contains glyphs from a child frame, handle the case that
that child frame dies before the saved state is restored.

(cherry picked from commit 56efab930b5c129aa9c87f99f657b7d704c6d5f9)

src/term.c

index bd48e1f3e55dca38c5be7bd41bb6c17f19705d3b..a7f7baa6e3ca7ff8b5421e5d2e1bee4b30ddaea6 100644 (file)
@@ -3121,9 +3121,7 @@ save_and_enable_current_matrix (struct frame *f)
 static void
 restore_desired_matrix (struct frame *f, struct glyph_matrix *saved)
 {
-  int i;
-
-  for (i = 0; i < saved->nrows; ++i)
+  for (int i = 0; i < saved->nrows; ++i)
     {
       struct glyph_row *from = saved->rows + i;
       struct glyph_row *to = f->desired_matrix->rows + i;
@@ -3133,7 +3131,23 @@ restore_desired_matrix (struct frame *f, struct glyph_matrix *saved)
       memcpy (to->glyphs[TEXT_AREA], from->glyphs[TEXT_AREA], nbytes);
       to->used[TEXT_AREA] = from->used[TEXT_AREA];
       to->enabled_p = from->enabled_p;
-      to->hash = from->hash;
+
+      bool need_new_hash = false;
+      for (int x = 0; x < f->desired_matrix->matrix_w; ++x)
+       {
+         struct glyph *glyph = to->glyphs[0] + x;
+         if (!FRAME_LIVE_P (glyph->frame))
+           {
+             glyph->frame = f;
+             glyph->face_id = DEFAULT_FACE_ID;
+             need_new_hash = true;
+           }
+       }
+
+      if (need_new_hash)
+       to->hash = row_hash (to);
+      else
+       to->hash = from->hash;
     }
 }