Subject: bug#77039: 31.0.50; Flickering on macOS

From: Gerd Möllmann <[email-masked]>
Date: Sun, 16 Mar 2025 20:25:59 +0100

Aaron Jensen <[email-masked]> writes:

> Hi,
>
> I've narrowed it down to the addition to frame in the glyph
> comparison. As far as I can tell, the attached patch removes the
> flickering for me. I saw the cursor blink once, but I couldn't
> reproduce that and I couldn't get it to do it again.
>
> The patch is not suitable for applying to master as it certainly
> breaks something int he tty child frame code, but hopefully it gives
> you an idea of what the problem might be. I'm going to experiment with
> accounting for the NULL frame in the space glyph and see if that
> helps.

Thanks Aaron, that was very helpful. I'm pretty sure it gave me right
idea, namely... This in adjust_glyph_matrix

dispnew.c:
  505           while (row < end)
  506             {
  507               row->glyphs[LEFT_MARGIN_AREA] =
  508                 xnrealloc (row->glyphs[LEFT_MARGIN_AREA],
  509                            dim.width, sizeof (struct glyph));

means that glyphs in window-system windows are not zeroed. Which in turn
means that glyph::frame is not guaranteed to be NULL initially. And
because I falsely assumed that to be the case, I didn't change the code
producing glyphs for window-systems to set glyph::frame, which isn't
needed or used on window-systems. And in the end, the glyph comparisons
can fail.

Or so is the hypothesis...

Could you please try if the attached change works for you (without your
patch)?

diff --git a/src/dispnew.c b/src/dispnew.c
index 69b29aeac16..0a404d9e37f 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -504,9 +504,11 @@ adjust_glyph_matrix (struct window *w, struct glyph_matrix *matrix, int x, int y
 
 	  while (row < end)
 	    {
-	      row->glyphs[LEFT_MARGIN_AREA] =
-		xnrealloc (row->glyphs[LEFT_MARGIN_AREA],
-			   dim.width, sizeof (struct glyph));
+	      row->glyphs[LEFT_MARGIN_AREA]
+		= xnrealloc (row->glyphs[LEFT_MARGIN_AREA], dim.width,
+			     sizeof (struct glyph));
+	      memset (row->glyphs[LEFT_MARGIN_AREA], 0,
+		      dim.width * sizeof (struct glyph));
 	      /* The mode line, if displayed, never has marginal areas.  */
 	      if ((row == matrix->rows + dim.height - 1
 		   && !(w && window_wants_mode_line (w)))