pygame-ce
pygame-ce copied to clipboard
Maximizing a window invalidates the window surface
OS: Windows 10, Python: 3.9
import pygame
from pygame._sdl2 import Window
window = Window(resizable=True)
screen = window.get_surface()
clock = pygame.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
raise SystemExit
if event.type == pygame.KEYDOWN and event.key == pygame.K_1:
window.maximize()
screen.fill("white")
window.flip()
When I press 1, get pygame.error: Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface
Relevant to #2603
The bug can be fixed if you add a pygame.init(), because the init hook of window module is called when display module init, then the init hook sets the event watch.
Ah, I didn't notice it was just about the resizability!
Using pygame.display.set_mode with pygame.RESIZABLE this problem never surfaces, so it probably shouldn't here?
Using pygame.display.set_mode with pygame.RESIZABLE this problem never surfaces
The resize event watch of display module is set in set_mode(), so it's not influenced by this bug.
Sure. I’m saying that since this error can’t occur with pygame.display, it shouldn’t be able to occur with pygame.window.
I see two ways to resolve this
Windowconstructor callspygame.display.init()Windowconstructor requirespygame.display.init()to be called already, and error otherwise
I prefer the second way. pygame.display.set_mode actually goes the first way however
The way I see it, the modern way is to make initializations more automatic. And it's precedented in display.set_mode.
But either option would be better than the current setup.