Subject: bug#60096: 29.0.60; Crash in format_mode_line_unwind_data

From: martin rudalics <[email-masked]>
Date: Sun, 18 Dec 2022 10:18:18 +0100

>>   >> Alternatively, we could exclude windows with a nil buffer in
 >>   >> add_window_to_list (think of the case that within the blurb
 >>   >> producing code someone wants to consult the window list).
 >>   >
 >>   > Maybe we should try this on master.  I indeed expected
 >>   > add_window_to_list to filter such invalid windows and was surprised
 >>   > that it didn't.  Basically, I don't understand how we never had such
 >>   > windows in the list before, since there's no code which actively
 >>   > removes them and thus protects the list from holding such windows.  I
 >>   > think we just have been lucky.
 >>
 >> Probably so far we never tried to call 'kill-buffer' from within
 >> 'set-window-configuration'.  If the only "live" window shows *scratch*,
 >> *scratch* gets killed and we kill a temporary buffer before we were able
 >> to recreate *scratch*, window_list will return the empty list.
 >
 > Why the empty list?  The buffer gets killed, but windows don't get
 > killed.  We still have the frame with at least two windows (including
 > the mini-window).  Right?

Not if we exclude windows with a nil buffer as suggested above.  The
delete_all_child_windows call in 'set-window-configuration' sets the
contents field of every live window on that frame to nil and as long as
we have not been able to get a live buffer for that window, it will stay
nil.  That's where all those windows with a nil buffer in your
investigations come from.  It's simply not safe to deal with windows
before 'set-window-configuration' has done its work completely.  If we
think of running Lisp in this time, we have to do it in a completely
restricted way: Any window, including the selected one, can legitimately
have a nil buffer then.

martin