Skip to content
Snippets Groups Projects
Commit 97c7ef0c authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

Program should exit better now. Catches KeyboardInterrupt in pygame_gui.py and quits properly

parent 103df462
No related branches found
No related tags found
1 merge request!15Resolve "Better exiting the programm and all threads"
Pipeline #42223 passed
import colorsys
import math
import sys
import numpy as np
import numpy.typing as npt
......@@ -401,15 +402,21 @@ class PyGameGUI:
# Game loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type in [pygame.KEYDOWN, pygame.KEYUP]:
self.handle_key_event(event)
self.handle_keys()
clock.tick(self.FPS)
state = self.simulator.get_state()
self.draw(state)
try:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type in [pygame.KEYDOWN, pygame.KEYUP]:
self.handle_key_event(event)
self.handle_keys()
clock.tick(self.FPS)
state = self.simulator.get_state()
self.draw(state)
except KeyboardInterrupt:
pygame.quit()
self.simulator.stop()
sys.exit()
pygame.quit()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment