Skip to content

Commit 9566281

Browse files
committed
updated unsafe run tracking
1 parent d4635b6 commit 9566281

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

chess.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,6 @@ def set_screen_size(size: int):
333333
pygame.display.set_caption("Chess")
334334
pygame.display.set_icon(ICON)
335335

336-
running = True
337-
338336
ai_glob = False # if chess.py is "__main__" then this is the default it takes
339337

340338
LIGHT: Color = 230, 210, 170
@@ -854,9 +852,11 @@ def handle_promotion(gamestate: GameState, ai_promoting=False):
854852
print("if you are running the exe, and can see this terminal, you are running a pre-release or a debug release.")
855853

856854
def main(ai: bool | None=ai_glob):
857-
global running, ai_glob
855+
global ai_glob
858856
ai_glob = ai
859857
gamestate.reset()
858+
running = True # local running flag
859+
860860
while running:
861861
for event in pygame.event.get():
862862
if event.type == pygame.QUIT:
@@ -895,5 +895,6 @@ def main(ai: bool | None=ai_glob):
895895
if __name__ == "__main__":
896896
try:
897897
main(ai=ai_glob)
898-
except pygame.error:
899-
print("pygame has been closed in another module or location.")
898+
except pygame.error as e:
899+
if str(e) != "video system not initialized":
900+
raise # re-raise any other errors

menu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
)
4949

5050
clock: pygame.Clock = pygame.time.Clock()
51-
running: bool = True
51+
5252
def main():
53-
global running
53+
running = True
5454
while running:
5555
time_delta = clock.tick(60) / 1000.0
5656

settings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
pygame.display.set_icon(ICON)
1111

1212
clock: pygame.Clock = pygame.time.Clock()
13-
running: bool = True
1413

1514
theme_file = chess.resource_path("theme.json")
1615
manager = pygame_gui.UIManager((chess.WIDTH, chess.HEIGHT), theme_path=theme_file)
@@ -49,7 +48,7 @@
4948

5049

5150
def main():
52-
global running
51+
running: bool = True
5352
while running:
5453
time_delta = clock.tick(60) / 1000.0
5554

0 commit comments

Comments
 (0)