fix(app): callbacks after closing a window do nothing
public
fix(app): callbacks after closing a window do nothing Engine answers and timers could arrive after a window was closed, when get_application() is None, and raised in _movelist_update and _refresh_chrome. Closing now ends a playback (its timer too) and marks the window closed; _refresh, _refresh_chrome and _movelist_update return early. Found by the random test; regression test added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| Changeset | 251f018b8a062d559910f7237aae93dff787160e |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@nullachtvierzehn.de>, |
| Parents | b28fe33e3782 |
| Children | 12e981706f99 |
| Pushlog | by timo via ssh by timo via ssh |
modified schach/app.py +8 −0
| @@ -639,6 +639,8 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 639 | 639 | def _refresh(self): |
| 640 | 640 | """Brett und Leisten nachführen; danach die Invarianten prüfen (zustand.py), aber nur am |
| 641 | 641 | Ende des äußersten Aufrufs: dazwischen darf der Zustand halb umgebaut sein.""" |
| 642 | + if getattr(self, "closed", False): | |
| 643 | + return # Rückruf (Engine, Zeitgeber) nach dem Schließen | |
| 642 | 644 | self._refresh_depth = getattr(self, "_refresh_depth", 0) + 1 |
| 643 | 645 | try: |
| 644 | 646 | self._refresh_view() |
| @@ -718,6 +720,8 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 718 | 720 | self._start_thinking() |
| 719 | 721 | |
| 720 | 722 | def _refresh_chrome(self): |
| 723 | + if getattr(self, "closed", False): | |
| 724 | + return | |
| 721 | 725 | side = "Weiß" if self.human == chess.WHITE else "Schwarz" |
| 722 | 726 | if self._browsing(): |
| 723 | 727 | shown = self._board_at(self.browse_ply) |
| @@ -1717,6 +1721,8 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1717 | 1721 | |
| 1718 | 1722 | def _movelist_update(self): |
| 1719 | 1723 | """Zugliste samt Nebenvarianten vom Analysebrett; markiert, wo das Analysebrett gerade steht.""" |
| 1724 | + if getattr(self, "closed", False): | |
| 1725 | + return # z. B. eine Bewertung, die erst nach dem Schließen ankommt | |
| 1720 | 1726 | branches, self.list_nodes = self._list_variations() |
| 1721 | 1727 | selected = None |
| 1722 | 1728 | if self.demo is not None and self.demo.get("game") and not self._demo_real(self.demo["node"]): |
| @@ -2439,6 +2445,8 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 2439 | 2445 | if self._autosave_source: |
| 2440 | 2446 | GLib.source_remove(self._autosave_source) |
| 2441 | 2447 | self._autosave() |
| 2448 | + self._review_leave() # auch der Takt der Wiedergabe hört auf | |
| 2449 | + self.closed = True # Engine-Antworten, die noch unterwegs sind, laufen ins Leere | |
| 2442 | 2450 | return False |
| 2443 | 2451 | |
| 2444 | 2452 | |
modified tests/test_zustand_regression.py +12 −0
| @@ -164,5 +164,17 @@ class VerlassenTest(unittest.TestCase): | ||
| 164 | 164 | self.assertEqual(zustand.violations(win), []) |
| 165 | 165 | |
| 166 | 166 | |
| 167 | +class GeschlossenTest(unittest.TestCase): | |
| 168 | + def test_rueckrufe_nach_dem_schliessen_tun_nichts(self): | |
| 169 | + """Gefunden am 24.11.2026 vom Zufallstest (Seeds 1, 12, 13): Eine Engine-Antwort kam an, | |
| 170 | + nachdem das Fenster schon zu war; get_application() ist dann None, und _movelist_update | |
| 171 | + (über _wdl_elos) bzw. _refresh_chrome warfen AttributeError.""" | |
| 172 | + from schach.app import Window | |
| 173 | + | |
| 174 | + closed = types.SimpleNamespace(closed=True, get_application=lambda: None) | |
| 175 | + for method in (Window._refresh, Window._refresh_chrome, Window._movelist_update): | |
| 176 | + method(closed) # darf nichts anfassen | |
| 177 | + | |
| 178 | + | |
| 167 | 179 | if __name__ == "__main__": |
| 168 | 180 | unittest.main() |