Open mtav opened 2 years ago
After some reseacrh, I came across this, according to which:
you can't rely on graphics being accessible from multiple threads. You would have to transfer all your drawing to the main thread. You can still have threads running other logic.
So I fixed my problem with this patch (including a problem with the pygame window not closing properly by adding a pygame.quit() call):
diff --git a/pygame_cards/pygame_cards/game_app.py b/pygame_cards/pygame_cards/game_app.py
index d64ef91..aae0c43 100644
--- a/pygame_cards/pygame_cards/game_app.py
+++ b/pygame_cards/pygame_cards/game_app.py
@@ -238,8 +238,9 @@ class GameApp(object, metaclass=abc.ABCMeta):
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.stopped = True
- self.render_thread.join()
+ # self.render_thread.join()
self.game_controller.cleanup()
+ pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONUP:
self.process_mouse_event(False, self.is_double_click())
@@ -300,11 +301,15 @@ class GameApp(object, metaclass=abc.ABCMeta):
""" Runs endless loop where game logic and events processing are executed. """
while 1:
self.clock.tick(60)
+
+ self.render()
+ pygame.display.flip()
+
self.process_events()
self.execute_game_logic()
def execute(self):
""" Initializes game, starts rendering thread and starts game endless loop """
self.init_game()
- self.start_render_thread()
+ # self.start_render_thread()
self.run_game_loop()
It basically disables the separate render thread.
Maybe an option could be added for disabling multithreading? I suppose it could be GNU/Linux-specific issue or related to graphics drivers, but for now this works for me.
When I try to run the klondike example, I just get a screen that contains whatever was behind it before it appeared and the following error message in the terminal:
Here is what I did after a git clone:
System information: