Subject: bug#44502: 28.0.50; Emacs crash using new frame

From: Alan Mackenzie <[email-masked]>
Date: Sun, 8 Nov 2020 13:37:21 +0000

Hello, Eli and Andy.

On Sat, Nov 07, 2020 at 16:05:51 +0200, Eli Zaretskii wrote:
> > From: Andy Moreton <[email-masked]>
> > Date: Sat, 7 Nov 2020 13:27:30 +0000

> > Emacs crashed when using a new frame. After a bootstrap of master, I
> > could repeat the crash witht he following recipe:
> >    - Run "emacs -Q"
> >    - Type "C-x 5 2 RET" to create a new frame (which becomes selected)
> >    - Type "C-x C-f" and emacs crashes

> > I bisected this using the recipe above, with:
> >    git checkout master
> >    git bisect start
> >    git bisect bad
> >    git bisect good c3a20804a8

> > Bisect reports the bad commit as:
> >    2ecbf4cfae Allow minibuffer to stay in its original frame.
> >               (2020-11-05 Alan Mackenzie)

> Thanks.  Yes, the above recipe causes an assertion violation.  Alan,
> can you take a look, please?

Thanks for the backtrace, which was helpful.  I've committed the
following patch, which appears to fix the bug:

commit cfe8a73cab5e7a9c6a6fcc212bd9df980f233895 (HEAD -> master,
origin/master, origin/HEAD)
Author: Alan Mackenzie <[email-masked]>
Date:   Sun Nov 8 13:28:55 2020 +0000

    Don't set the selected window to the miniwindow on a frame change.

    Intended to fix bug #44502.

    * src/minibuf.c (move_minibuffer_onto_frame): Remove the lines of code which
    set the selected window to the minibuffer.

diff --git a/src/minibuf.c b/src/minibuf.c
index 068086ead8..8c19559b08 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -142,10 +142,6 @@ void move_minibuffer_onto_frame (void)

       set_window_buffer (sf->minibuffer_window, buffer, 0, 0);
       minibuf_window = sf->minibuffer_window;
-      if (EQ (XWINDOW (minibuf_window)->frame, selected_frame))
-        /* The minibuffer might be on another frame. */
-        Fset_frame_selected_window (selected_frame, sf->minibuffer_window,
-                                    Qnil);
       set_window_buffer (of->minibuffer_window, get_minibuffer (0), 0, 0);
     }
 }

> Here's a backtrace from an unoptimized build:

>   window.c:554: Emacs fatal error: assertion failed: EQ (window, selected_window)

>   Thread 1 hit Breakpoint 1, terminate_due_to_signal (sig=22,
>       backtrace_limit=2147483647) at emacs.c:378
>   378       signal (sig, SIG_DFL);

[ .... ]

>   Lisp Backtrace:
>   "redisplay_internal (C function)" (0x0)
>   "read-from-minibuffer" (0x82c8a0)
>   "completing-read-default" (0x82cf00)
>   "completing-read" (0x82d210)
>   "read-file-name-default" (0x82d9c0)
>   "read-file-name" (0x82dfa0)
>   "find-file-read-args" (0x82e560)
>   "byte-code" (0x82ea18)
>   "call-interactively" (0x82ef80)
>   "command-execute" (0x82f5c8)

-- 
Alan Mackenzie (Nuremberg, Germany).