fix(gui): stop the UI rebuild from destroying the registry's windows#40
Merged
Conversation
Two swallowed teardown crashes from a field crash log had one cause: App._build_ui
rebuilds by destroying every child of the root window, and a Toplevel is a child of
the root. The open panel windows died there, so the rebuild that follows a language
switch ran close() on windows that no longer existed - recording TclError("bad window
path name") and, less visibly, dropping the geometry the user had just set (the window
came back where it was last CLOSED).
- _build_ui skips the Toplevels the registry owns (new WindowManager.toplevels)
- PanelWindow._save_geometry no-ops when the window is already gone
- bind_wraplength._resize no-ops when the label is gone: the <Configure> binding
lives on the CONTAINER, which outlives the label, and nothing unbinds it - so this
was one dead handler per rebuild, each recording on every resize, not a one-off race
- tests/fake_tk.py now models destruction (dead widget, real winfo_exists, TclError
from configure/geometry); without it no test could catch either bug, and a
winfo_exists guard would have read as "destroyed" for every widget on the fake
All four new tests verified by mutation: each guard removed in turn, each test goes
red. Full suite green (659 passed).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Two swallowed GUI teardown crashes from a real field
crashes.ndjson(bothswallowed/debug):gui.windows—TclError: bad window path name ".!toplevel2"in_save_geometrygui.labels—TclError: invalid command name ".!label"in_resizeThey turned out to share one cause, and the trigger was not closing a window but a language switch:
App._build_uirebuilds the UI by destroying every child of the root window, and aToplevelis a child of the root. The open panel windows (e.g. Settings) died there, so thewindows.rebuild()that follows ranclose()on windows that no longer existed.That cost two things, not one:
TclErrorper switch, andThe label crash was not a one-off teardown race either:
wrapping_labelbinds<Configure>on the container, which outlives the label, and nothing unbinds it. Every rebuild leaves one more dead handler behind, each recording on every subsequent resize.Changes
App._build_uiskips the Toplevels the registry owns (newWindowManager.toplevels()); window lifecycle belongs to the registry, not the rebuild.PanelWindow._save_geometryno-ops when the window is already gone (winfo_exists).bind_wraplength._resizeno-ops when the label is gone.on_closealready closed the windows before persisting UI state (so geometry survives quit); that ordering had no test and now has one.tests/fake_tk.pymade honest about destruction:destroy()kills children and leaves the widget dead,winfo_exists()is real, andconfigure()/geometry()raiseTclErrorafterwards — the way Tk does. Without this none of the guards could be tested, and awinfo_exists()guard would read as "destroyed" for every widget on the fake (becauseW.__getattr__answers any unknown attribute with a no-opNone).Reviewer notes
windows.close_all()inon_close(the call was already there); the duplicate was removed and the test now guards the real call and its ordering._build_uialso re-addsroot.bind("<Configure>", self._on_root_configure, add="+")on every rebuild without removing the old one, so that handler multiplies the same way. It holds theApp, not a dead widget, so it costs duplicated work per resize rather than crash records. Noted inCHANGELOG-INTERNAL.md.crashes.ndjsonbefore and the mechanism reproduced.Checklist
python -m pytest testspasses locally. (659 passed; run elevated, so no admin-only deselects needed.)tests/for the style). Four added, all mutation-verified.lang/en.jsonandlang/pl.jsonupdated. (No new UI text in this change — nolang/edits needed.)CHANGELOG.md; technical ones and new tests inCHANGELOG-INTERNAL.md, under[Unreleased].type(scope): summary).VERSION.txt.🤖 Generated with Claude Code