Public repository: timo / schach

Reader

Ein aufgeräumtes Schach-Programm für GNOME

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>
Changeset251f018b8a062d559910f7237aae93dff787160e
Author (claimed)Timo Stolz <timo.stolz@nullachtvierzehn.de>,
Parentsb28fe33e3782
Children12e981706f99
Pushlog
by timo via ssh
by timo via ssh

modified schach/app.py +8 −0

@@ -639,6 +639,8 @@ class Window(OnlineMixin, PuzzleMixin, O
639639
     def _refresh(self):
640640
         """Brett und Leisten nachführen; danach die Invarianten prüfen (zustand.py), aber nur am
641641
         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
642644
         self._refresh_depth = getattr(self, "_refresh_depth", 0) + 1
643645
         try:
644646
             self._refresh_view()
@@ -718,6 +720,8 @@ class Window(OnlineMixin, PuzzleMixin, O
718720
         self._start_thinking()
719721
 
720722
     def _refresh_chrome(self):
723
+        if getattr(self, "closed", False):
724
+            return
721725
         side = "Weiß" if self.human == chess.WHITE else "Schwarz"
722726
         if self._browsing():
723727
             shown = self._board_at(self.browse_ply)
@@ -1717,6 +1721,8 @@ class Window(OnlineMixin, PuzzleMixin, O
17171721
 
17181722
     def _movelist_update(self):
17191723
         """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
17201726
         branches, self.list_nodes = self._list_variations()
17211727
         selected = None
17221728
         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
24392445
         if self._autosave_source:
24402446
             GLib.source_remove(self._autosave_source)
24412447
             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
24422450
         return False
24432451
 
24442452
 

modified tests/test_zustand_regression.py +12 −0

@@ -164,5 +164,17 @@ class VerlassenTest(unittest.TestCase):
164164
         self.assertEqual(zustand.violations(win), [])
165165
 
166166
 
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
+
167179
 if __name__ == "__main__":
168180
     unittest.main()