Subject: Re: bug#14161: assertion failed: EQ (selected_window, XFRAME (selected_frame)->selected_window)

From: Stefan Monnier <[email-masked]>
Date: Mon, 08 Apr 2013 14:06:22 -0400

> 1) ./src/emacs -nw -Q
> 2) M-x make-frame-on-display :0
> 3) Move mouse to new X frame and left-click;
> 4) Move mouse back to TTY frame and left-click;
> 5) Press C-g staying in TTY frame ==>

> #2  0x000000000065d92d in die (msg=0x79db98 "assertion failed: EQ
> (selected_window, XFRAME (selected_frame)->selected_window)", file=
>      0x79b560 "src/xdisp.c", line=11427) at src/alloc.c:6522

I've installed the patch below which seems to fix this problem for me.

        Stefan

=== modified file 'src/window.c'
--- src/window.c	2013-04-02 01:54:56 +0000
+++ src/window.c	2013-04-08 17:58:36 +0000
@@ -485,12 +485,6 @@
   w = XWINDOW (window);
   w->frozen_window_start_p = 0;
 
-  if (NILP (norecord))
-    {
-      w->use_time = ++window_select_count;
-      record_buffer (w->contents);
-    }
-
   /* Make the selected window's buffer current.  */
   Fset_buffer (w->contents);
 
@@ -515,6 +509,15 @@
 
   select_window_1 (window, inhibit_point_swap);
 
+  /* record_buffer can run QUIT, so make sure it is run only after we have
+     re-established the invariant between selected_window and selected_frame,
+     otherwise the temporary broken invariant might "escape" (bug#14161).  */
+  if (NILP (norecord))
+    {
+      w->use_time = ++window_select_count;
+      record_buffer (w->contents);
+    }
+
   bset_last_selected_window (XBUFFER (w->contents), window);
   windows_or_buffers_changed++;
   return window;