Skip to content

Commit

Permalink
fix: catch pygame exception for graceful exit (#2)
Browse files Browse the repository at this point in the history
This fixes a timing issue where a call to flip the pygame screen may
happen even after pygame was quit preventing a graceful exit.
  • Loading branch information
JeanElsner committed Jul 6, 2024
1 parent 970fa1e commit 2a5c1ba
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/garmi_gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,17 @@ def _run(self) -> None:
return

while self.running:
for event in pygame.event.get():
if (
event.type == pygame.QUIT
or event.type == pygame.KEYDOWN
and event.key == pygame.K_ESCAPE
):
self.running = False
pygame.display.flip()
try:
for event in pygame.event.get():
if (
event.type == pygame.QUIT
or event.type == pygame.KEYDOWN
and event.key == pygame.K_ESCAPE
):
self.running = False
pygame.display.flip()
except pygame.error:
self.running = False

self.clock.tick(10) # Throttle loop to reduce CPU usage

Expand Down

0 comments on commit 2a5c1ba

Please sign in to comment.