GNU bug report logs - #54028
Window is not a valid window

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Wed, 16 Feb 2022 18:54:01 UTC

Severity: normal

Fixed in version 28.1

Done: martin rudalics <rudalics <at> gmx.at>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 54028 in the body.
You can then email your comments to 54028 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#54028; Package emacs. (Wed, 16 Feb 2022 18:54:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> linkov.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 16 Feb 2022 18:54:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: bug-gnu-emacs <at> gnu.org
Subject: Window is not a valid window
Date: Wed, 16 Feb 2022 20:50:10 +0200
I don't know if the author of
https://www.reddit.com/r/emacs/comments/sthusa/window_xxx_is_not_a_valid_window_on_switching_tabs/
will report the bug here, but since it's easily reproducible,
here is the short test case, just evaluate this:

(window-state-put
 '(((min-height . 8)
    (min-width . 20)
    (min-height-ignore . 4)
    (min-width-ignore . 12)
    (min-height-safe . 2)
    (min-width-safe . 4)
    (min-pixel-height . 168)
    (min-pixel-width . 200)
    (min-pixel-height-ignore . 84)
    (min-pixel-width-ignore . 120)
    (min-pixel-height-safe . 42)
    (min-pixel-width-safe . 40))
   vc
   (pixel-width . 2048)
   (pixel-height . 1008)
   (total-width . 205)
   (total-height . 48)
   (normal-height . 1.0)
   (normal-width . 1.0)
   (combination-limit)
   (hc
    (pixel-width . 2048)
    (pixel-height . 798)
    (total-width . 205)
    (total-height . 38)
    (normal-height . 0.7916666666666667)
    (normal-width . 1.0)
    (combination-limit)
    (leaf
     (pixel-width . 1028)
     (pixel-height . 798)
     (total-width . 103)
     (total-height . 38)
     (normal-height . 1.0)
     (normal-width . 0.5)
     (buffer "test.py"
	     (selected . t)
	     (hscroll . 0)
	     (fringes 8 8 nil nil)
	     (margins nil)
	     (scroll-bars nil 2 t nil 0 t nil)
	     (vscroll . 0)
	     (dedicated)
	     (point . 72)
	     (start . 1))
     (prev-buffers
      ("cards.js" 367 1480)
      ("__init__.pyi" 21558 22551)
      ("*helpful variable: completion-at-point-functions*" 244 1615)
      ("DHU236/Lectures.org" 93135 95371)
      ("DHU236/Assignments.org" 62643 63879)
      ("DHU236/Pages.org" 591 2208)
      ("org-lms.org" 214188 214910)
      ("emacs-init.org" 127438 130382)
      ("corfu.el" 3265 4543)
      ("DHU236/Announcements.org" 12275 14041)))
    (leaf
     (last . t)
     (pixel-width . 1020)
     (pixel-height . 798)
     (total-width . 102)
     (total-height . 38)
     (normal-height . 1.0)
     (normal-width . 0.5)
     (buffer "*tree-sitter-tree: cards.js*"
	     (selected)
	     (hscroll . 0)
	     (fringes 8 8 nil nil)
	     (margins nil)
	     (scroll-bars nil 2 t nil 0 t nil)
	     (vscroll . 0)
	     (dedicated)
	     (point . 1)
	     (start . 1))))
   (leaf
    (last . t)
    (pixel-width . 2048)
    (pixel-height . 210)
    (total-width . 205)
    (total-height . 10)
    (normal-height . 0.20833333333333331)
    (normal-width . 1.0)
    (parameters
     (window-side . bottom)
     (window-slot . 0))
    (buffer "*tree-sitter-query-builder*"
	    (selected)
	    (hscroll . 0)
	    (fringes 8 8 nil nil)
	    (margins nil)
	    (scroll-bars nil 2 t nil 0 t nil)
	    (vscroll . 0)
	    (dedicated . side)
	    (point . 1)
	    (start . 1))))
 nil 'safe)

It fails with:

  Debugger entered--Lisp error: (error "#<window 9> is not a valid window")
    error("%s is not a valid window" #<window 9>)
    window-normalize-window(#<window 9>)
    window-deletable-p(#<window 9>)
    window-state-put




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#54028; Package emacs. (Thu, 17 Feb 2022 10:07:02 GMT) Full text and rfc822 format available.

Message #8 received at 54028 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Juri Linkov <juri <at> linkov.net>, 54028 <at> debbugs.gnu.org
Subject: Re: bug#54028: Window is not a valid window
Date: Thu, 17 Feb 2022 11:06:13 +0100
[Message part 1 (text/plain, inline)]
> I don't know if the author of
> https://www.reddit.com/r/emacs/comments/sthusa/window_xxx_is_not_a_valid_window_on_switching_tabs/
> will report the bug here,

Please encourage the author again to report such bugs here.

> but since it's easily reproducible,
> here is the short test case, just evaluate this:
>
> (window-state-put
> ...
>   nil 'safe)
>
> It fails with:
>
>    Debugger entered--Lisp error: (error "#<window 9> is not a valid window")
>      error("%s is not a valid window" #<window 9>)
>      window-normalize-window(#<window 9>)
>      window-deletable-p(#<window 9>)
>      window-state-put

I think the attached fixes it, please check.  I have no idea whether the
state is restored as intended, though.

Thanks, martin
[window-state-put.diff (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#54028; Package emacs. (Thu, 17 Feb 2022 17:49:03 GMT) Full text and rfc822 format available.

Message #11 received at 54028 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 54028 <at> debbugs.gnu.org
Subject: Re: bug#54028: Window is not a valid window
Date: Thu, 17 Feb 2022 19:34:35 +0200
>> I don't know if the author of
>> https://www.reddit.com/r/emacs/comments/sthusa/window_xxx_is_not_a_valid_window_on_switching_tabs/
>> will report the bug here,
>
> Please encourage the author again to report such bugs here.

Maybe they hesitate to use e-mail?

>> but since it's easily reproducible,
>> here is the short test case, just evaluate this:
>>
>> (window-state-put
>> ...
>>   nil 'safe)
>>
>> It fails with:
>>
>>    Debugger entered--Lisp error: (error "#<window 9> is not a valid window")
>>      error("%s is not a valid window" #<window 9>)
>>      window-normalize-window(#<window 9>)
>>      window-deletable-p(#<window 9>)
>>      window-state-put
>
> I think the attached fixes it, please check.

Thanks, it doesn't fail anymore, but wasn't the problem
somewhere in the invalid window state?

> I have no idea whether the state is restored as intended, though.

Is it possible to find what window was invalid in this window state?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#54028; Package emacs. (Sat, 19 Feb 2022 09:39:01 GMT) Full text and rfc822 format available.

Message #14 received at 54028 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Juri Linkov <juri <at> linkov.net>
Cc: 54028 <at> debbugs.gnu.org
Subject: Re: bug#54028: Window is not a valid window
Date: Sat, 19 Feb 2022 10:38:45 +0100
> Thanks, it doesn't fail anymore, but wasn't the problem
> somewhere in the invalid window state?

No.  The sequence of events leading to the bug is the following:
'window-state-put' has

      ;; Work on the windows of a temporary buffer to make sure that
      ;; splitting proceeds regardless of any buffer local values of
      ;; `window-size-fixed'.  Release that buffer after the buffers of
      ;; all live windows have been set by `window--state-put-2'.
      (with-temp-buffer
	(set-window-buffer window (current-buffer))
	(window--state-put-1 state window nil totals pixelwise)
	(window--state-put-2 ignore pixelwise))

When this calls 'window--state-put-2', the window's buffer is *temp*.
'window--state-put-2' has:

	    ;; We don't want to raise an error in case the buffer does
	    ;; not exist anymore, so we switch to a previous one and
	    ;; save the window with the intention of deleting it later
	    ;; if possible.
	    (switch-to-prev-buffer window)
	    (push window window-state-put-stale-windows)))))))

Here, since window has no previous buffer, *temp* remains that window's
buffer.  Now *temp* gets killed when the 'with-temp-buffer' form exits
and, since its window is deletable, that window simply gets deleted via
‘kill-buffer’.  Back in 'window-state-put' we do

      (while window-state-put-stale-windows
        (let ((window (pop window-state-put-stale-windows)))
          (when (eq (window-deletable-p window) t)
	    (delete-window window))))

and here the window is no more valid because it has been deleted in
the meantime.

So AFAICT we start with a valid window state 'window-state-put' can't
handle.  I have no idea why this didn't hit us before.  Maybe, because
such windows usually have a previous buffer 'switch-to-prev-buffer' can
switch to.

>> I have no idea whether the state is restored as intended, though.
>
> Is it possible to find what window was invalid in this window state?

There is none as I tried to explain above.  The question is rather
whether the restored state resembles the saved state satisfactorily.
But that only the OP can tell.

martin


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#54028; Package emacs. (Mon, 21 Feb 2022 09:09:02 GMT) Full text and rfc822 format available.

Message #17 received at 54028 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Juri Linkov <juri <at> linkov.net>, 54028 <at> debbugs.gnu.org
Cc: "eliz <at> gnu.org" <eliz <at> gnu.org>
Subject: Re: bug#54028: Window is not a valid window
Date: Mon, 21 Feb 2022 10:07:59 +0100
Eli, is the below OK to install on the release branch?  It's a trivial
safety check that would fix this bug.

Thanks, martin


--- a/lisp/window.el
+++ b/lisp/window.el
@@ -6394,7 +6394,8 @@ window-state-put
 	(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)
+	  (when (and (window-valid-p window)
+                     (eq (window-deletable-p window) t))
 	    (delete-window window))))
       (window--check frame))))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#54028; Package emacs. (Mon, 21 Feb 2022 12:31:03 GMT) Full text and rfc822 format available.

Message #20 received at 54028 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 54028 <at> debbugs.gnu.org, juri <at> linkov.net
Subject: Re: bug#54028: Window is not a valid window
Date: Mon, 21 Feb 2022 14:30:17 +0200
> Date: Mon, 21 Feb 2022 10:07:59 +0100
> From: martin rudalics <rudalics <at> gmx.at>
> Cc: "eliz <at> gnu.org" <eliz <at> gnu.org>
> 
> Eli, is the below OK to install on the release branch?  It's a trivial
> safety check that would fix this bug.

Yes, thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#54028; Package emacs. (Mon, 21 Feb 2022 16:52:02 GMT) Full text and rfc822 format available.

Message #23 received at 54028 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 54028 <at> debbugs.gnu.org, juri <at> linkov.net
Subject: Re: bug#54028: Window is not a valid window
Date: Mon, 21 Feb 2022 17:50:54 +0100
close 54028 28.1
quit

>> Eli, is the below OK to install on the release branch?  It's a trivial
>> safety check that would fix this bug.
>
> Yes, thanks.

Fixed with commit 68d134cf0f784601e50cefc4056eb0ace510a982 on the
release branch.  Closing this bug.

Thanks, martin




bug marked as fixed in version 28.1, send any further explanations to 54028 <at> debbugs.gnu.org and Juri Linkov <juri <at> linkov.net> Request was from martin rudalics <rudalics <at> gmx.at> to control <at> debbugs.gnu.org. (Mon, 21 Feb 2022 16:52:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 22 Mar 2022 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 86 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.