> The answer, which I sort of suspected, is that it never hit that > breakpoint at all before the assertion fires. You're right. In + if (!NILP (Fstring_equal (XBUFFER (w->contents)->name_, + build_string ("*Server*")))) + best_window = Qt; + /* Undedicate WINDOW. */ wset_dedicated (w, Qnil); /* Make WINDOW show the buffer returned by @@ -3048,6 +3061,8 @@ window_loop (enum window_loop type, Lisp_Object obj, bool mini, if (EQ (window, selected_window) && XBUFFER (w->contents) == current_buffer) Fset_buffer (w->contents); + + replace_buffer_in_windows_safely_count += 1; replace_buffer_in_windows_safely_count is incremented regardless of whether W's buffer is *Server* or not. In either case the assertion would not fail. So once we are here everything is all right and the bug must be that we do not get here. I attach the next patch. Please put a breakpoint at the replace_buffer_in_windows_safely_count = 0; and try to step through the rest of this function with GDB. And if you don't hit it, the detection logic went wrong ... martin