Subject: bug#39977: 28.0.50; Unhelpful stack trace

From: Eli Zaretskii <[email-masked]>
Date: Sat, 07 Mar 2020 20:50:42 +0200

> From: Madhu <[email-masked]>
> Date: Sat, 07 Mar 2020 23:13:16 +0530
> 
> Thanks Eli, Following up on the emacs-devel message, I recompiled emacs
> and get substantially the same stack trace. This is with my ~/.emacs and
> all my local customizations loaded.
> 
> when evaluating a form in a sly lisp buffer with
>  (break)
> M-x sly-eval-last-sexp
> pops up a sly debug window in a new frame
> quitting the window (and frame) tries to select the previous window
> and the crash apparently happens at this point. I'm attaching the
> backtraces as attachments
> 
> With a little guidance I expect to be able to investigate this further

Thanks.  Please try the patch below, and tell if it makes the crash
go away.

diff --git a/src/window.c b/src/window.c
index 8cdad27..863fac4 100644
--- a/src/window.c
+++ b/src/window.c
@@ -541,8 +541,11 @@ select_window (Lisp_Object window, Lisp_Object norecord,
   else
     redisplay_other_windows ();
 
-  sf = SELECTED_FRAME ();
-  if (XFRAME (WINDOW_FRAME (w)) != sf)
+  if (FRAMEP (selected_frame) && FRAME_LIVE_P (XFRAME (selected_frame)))
+    sf = XFRAME (selected_frame);
+  else
+    sf = NULL;
+  if (!sf || XFRAME (WINDOW_FRAME (w)) != sf)
     {
       fset_selected_window (XFRAME (WINDOW_FRAME (w)), window);
       /* Use this rather than Fhandle_switch_frame