Subject: Window is not a valid window

From: Juri Linkov <[email-masked]>
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