* lisp/window.el (window-state-put): Make sure window is live
before calling 'window-deletable-p' on it (Bug#54028).
(window--state-put-2 ignore pixelwise))
(while window-state-put-stale-windows
(let ((window (pop window-state-put-stale-windows)))
- (when (eq (window-deletable-p window) t)
+ ;; Avoid that 'window-deletable-p' throws an error if window
+ ;; was already deleted when exiting 'with-temp-buffer' above
+ ;; (Bug#54028).
+ (when (and (window-valid-p window)
+ (eq (window-deletable-p window) t))
(delete-window window))))
(window--check frame))))