[Bug Report] The Incredible Shrinking Window! (PyGame surface resizes in infinite loop)
See original GitHub issueDescribe the bug
I’m trying to run the example code given for the play
utility function.
However, when I run this code, the window shrinks by 2 pixels for every frame rendered.
I think this is because my window manager adds a 1px
border to the game window.
The problem seems to come from the following code in play.py
on lines 116-118:
elif event.type == VIDEORESIZE:
self.video_size = event.size
self.screen = pygame.display.set_mode(self.video_size)
If I add print(event)
to this elif
block, I get the following output:
<Event(32769-VideoResize {'size': (598, 398), 'w': 598, 'h': 398})>
<Event(32769-VideoResize {'size': (596, 396), 'w': 596, 'h': 396})>
<Event(32769-VideoResize {'size': (594, 394), 'w': 594, 'h': 394})>
<Event(32769-VideoResize {'size': (592, 392), 'w': 592, 'h': 392})>
<Event(32769-VideoResize {'size': (590, 390), 'w': 590, 'h': 390})>
Removing the line
self.screen = pygame.display.set_mode(self.video_size)
fixes the problem. I believe this is because setting the video mode creates an infinite loop where a new VIDEORESIZE
event is created, triggering set_mode
again.
Code example
#!/usr/bin/env python3
import numpy as np
import gymnasium as gym
from gymnasium.utils.play import play
import gymnasium as gym
from gymnasium.utils.play import play
play(gym.make("CarRacing-v2", render_mode="rgb_array"), keys_to_action={
"w": np.array([0, 0.7, 0]),
"a": np.array([-1, 0, 0]),
"s": np.array([0, 0, 1]),
"d": np.array([1, 0, 0]),
"wa": np.array([-1, 0.7, 0]),
"dw": np.array([1, 0.7, 0]),
"ds": np.array([1, 0, 1]),
"as": np.array([-1, 0, 1]),
}, noop=np.array([0,0,0]))
System info
Installation method: pip install
gymnasium version: 0.26.3
OS: Arch Linux
Python version: 3.10.8
Additional context
No response
Checklist
- I have checked that there is no similar issue in the repo
Issue Analytics
- State:
- Created 9 months ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Issues · Farama-Foundation/Gymnasium - GitHub
[Bug Report] The Incredible Shrinking Window! (PyGame surface resizes in infinite loop) bug Something isn't working. #187 opened 8 hours ago by statusfailed....
Read more >Allowing resizing window pyGame - python - Stack Overflow
The answer for this problem (allow the Pygame window and the surface inside it to resize) is simply to recreate the resizable window...
Read more >Allowing resizing window in PyGame - GeeksforGeeks
In this article, we will learn How to allow resizing a PyGame Window. Game programming is very rewarding nowadays and it can also...
Read more >The Real Python Podcast
We talk about a Real Python tutorial that covers configuring a Windows coding ... A Better Pygame Main Loop – Improving your game's...
Read more >2008-April.txt - Python mailing list
Except MySQL is reporting a wrong installation path. > I haven't found any other topic in the list about this problem. Looks like...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Markus28 Yep, the code in #190 fixes it. Also the window is resizable, which is neat 😃
I don’t think that is necessary as unless users try to resize the window then this should be completely backward compatibility