Subject: bug#24642: 26.0.50; Missing mode-line on initial frame

From: Eli Zaretskii <[email-masked]>
Date: Sun, 20 Nov 2016 18:23:13 +0200

> Date: Sat, 08 Oct 2016 18:17:29 +0200
> From: martin rudalics <[email-masked]>
> 
> With the following file missing-mode-line.el
> 
> 
> (defvar old (selected-frame))
> (defvar new (make-frame '((minibuffer . nil))))
> 
> (set-frame-width new 1640 nil t)
> (set-frame-width old 400 nil t)
> (set-frame-position new 0 0)
> (set-frame-position old -1 -40)
> 
> 
> and
> 
> emacs -Q -load "~/missing-mode-line.el"
> 
> I get on Windows XP two frames where the root window of the smaller one
> has a missing mode-line.  The mode-line reappears when that frame gets
> focus.  It's a minor issue but cannot be reproduced here with Emacs 25.
> 
> It's easily possible that I introduced the bug myself but I don't recall
> changing anything in this area.  So if this rings a bell ...

Sorry for a late response.

In fact, not just the mode line was missing, but the entire frame
contents was not displayed, just an empty frame.

No bells rang here, but the patch below solves this for me.  Does it
make sense?  (Don't ask me how it works on emacs-25, it looks like
some lucky coincidence with timing of the WM_PAINT message and the way
we set windows_or_buffers_changed.)

diff --git a/src/w32term.c b/src/w32term.c
index e8d66c9..ae0f741 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -4628,11 +4628,18 @@ w32_read_socket (struct terminal *terminal,
 		}
 	      else
 		{
-		  HDC hdc = get_frame_dc (f);
+		  /* Erase background again for safety.  But don't do
+		     that if the frame's 'garbaged' flag is set, since
+		     in that case expose_frame will do nothing, and if
+		     the various redisplay flags happen to be unset,
+		     we are left with a blank frame.  */
+		  if (!FRAME_GARBAGED_P (f))
+		    {
+		      HDC hdc = get_frame_dc (f);
 
-		  /* Erase background again for safety.  */
-		  w32_clear_rect (f, hdc, &msg.rect);
-		  release_frame_dc (f, hdc);
+		      w32_clear_rect (f, hdc, &msg.rect);
+		      release_frame_dc (f, hdc);
+		    }
 		  expose_frame (f,
 				msg.rect.left,
 				msg.rect.top,
diff --git a/src/xdisp.c b/src/xdisp.c
index c045ced..1420a4a 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -14116,6 +14116,7 @@ redisplay_internal (void)
               if (f->updated_p)
                 {
 		  f->redisplay = false;
+		  f->garbaged = false;
                   mark_window_display_accurate (f->root_window, true);
                   if (FRAME_TERMINAL (f)->frame_up_to_date_hook)
                     FRAME_TERMINAL (f)->frame_up_to_date_hook (f);