Closed leestarb closed 1 year ago
Hello, can you provide a minimal working example to test this bug? Thanks
Hello, can you provide a minimal working example to test this bug? Thanks
Hello, dear ppizarror.
Here is a simple example of the issue: https://tempfile.io/en/ynBUL0wGEjlVI8g/file (This file will be deleted after 7 days!)
Calling pygame.event.clear() after your play loop has exited seems to make it behave like you are expecting:
def start_playing():
Gameplay().play()
pygame.event.clear() # Prevent menu from seeing pygame.QUIT
self.configure_window() # This is needed to return menu's size and caption
That lets the menu's internal loop resume without exiting.
I haven't driven the game menus using menu.mainloop() in my project so there might be another approach I am oblivious of.
Calling pygame.event.clear() after your play loop has exited seems to make it behave like you are expecting:
def start_playing(): Gameplay().play() pygame.event.clear() # Prevent menu from seeing pygame.QUIT self.configure_window() # This is needed to return menu's size and caption
That lets the menu's internal loop resume without exiting.
I haven't driven the game menus using menu.mainloop() in my project so there might be another approach I am oblivious of.
Thanks! That is right direction. I'm investigating the event queue. Looks like it is a bug of pygame.
I started using pygame.event.get(pygame.QUIT)
to check for quitting. Instead of this (as I used before) I should iterate over pygame.event.get()
and check whether there is event with type pygame.QUIT
. This solves the issue.
But also, using pygame.event.get(pygame.QUIT)
and adding below pygame.event.clear()
or pygame.event.get()
works.
Not sure why this happens. That requires more investigation to understand the nature of this. At least, for me, the issue is solved.
Thank you for help, @bluefish2020 ! =)
Environment information Describe your environment information, such as:
The problem I start my menu with the mainloop method. In the menu I choose button to start my game. In my game I use while loop to draw and process my game. When I get pygame.QUIT event I break the loop. The bgfun function is called 1 time, I see black screened window and the process instantly ends with 0 code.
Expected behavior After breaking the loop, the menu must continue running.
Additional context I started experiencing this problem after making my game object oriented. So I use a class to control the menu and a class to process my game. I also start my game from outer scope (I create my menu controller class, which initialises pygame and menu and then runs it with mainloop method with pygame.display.get_surface() surface. I was not experiencing this issue when everything was in the same file, I just had several functions to manage the menu and the gameplay!
So I guess the problem is in that the menu loop dies? Please help!