pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
827 stars 133 forks source link

Calling a second time ``pygame.display.set_mode`` with ``vsync`` and ``vsync`` already enabled doesn't work correctly #2571

Open bilhox opened 10 months ago

bilhox commented 10 months ago

Environment:

Current behavior:

If you call pygame.display.set_mode with vsync enabled and then again with vsync enabled, the screen is black (like you lost the hand on the screen) and when you resize, the rest of the window is transparent.

Expected behavior:

You don't lost the hand on the screen, and it correctly resizes. Note : If you quit pygame between the two calls, the problem is fixed, could you tell me if it's what we should do ?

Screenshots

image Capture d'écran 2023-11-19 142026

Test program:

import pygame
import math

pygame.init()

screen = pygame.display.set_mode([800, 800], flags=pygame.RESIZABLE+pygame.SCALED, vsync=1)
screen2 = pygame.display.set_mode([900, 800], flags=pygame.RESIZABLE+pygame.SCALED, vsync=1)

clock = pygame.Clock()
pos = []
timer = 0

running = True

while running:

    dt = clock.tick() / 1000
    timer += dt

    screen.fill("black")

    pos = [400 + 40*math.cos(5*timer) + 20*math.cos(10*timer) + 200*math.cos(timer), 400 + 20*math.sin(10*timer) + 40*math.sin(5*timer) + 200*math.sin(timer)]

    pygame.draw.circle(screen, "red", pos, 20)

    pygame.display.flip()

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            running = False
Starbuck5 commented 10 months ago

Is this similar to https://github.com/pygame-community/pygame-ce/issues/2376?

bilhox commented 10 months ago

Is this similar to https://github.com/pygame-community/pygame-ce/issues/2376?

No 🤔

Matiiss commented 10 months ago

Despite a little bit of stuttering at first, the test program works just fine for me (can manually resize it too) on both pygame-ce 2.3.2 (SDL 2.26.5, Python 3.12.0) and pygame-ce 2.4.0.dev3 (SDL 2.26.5, Python 3.12.0) (current main). On Windows 10 though.

Does it just get stuck for you like in the screenshots?

bilhox commented 10 months ago

Yup, I lose control of the window surface, I can resize the window, but the result looks just like in the screenshots

bilhox commented 9 months ago

Sending this GIF file to illustrate the problem : what_happened

MyreMylar commented 3 months ago

While tinkering with this in the current main I continually got a pygame.error:

Traceback (most recent call last):
  File "C:\Users\dan\Programming\scrap\soundfont_testing.py", line 6, in <module>
    pygame.display.set_mode([800, 600], flags=pygame.SCALED)
pygame.error: failed to create renderer

I boiled it down to this:

import pygame

pygame.init()

pygame.display.set_mode([800, 600])
pygame.display.set_mode([800, 600], flags=pygame.SCALED)
bilhox commented 3 days ago

@MyreMylar It seems that something happened between 2.5.0 and 2.5.1, because now it segfaults. The debug infos :

pygame-ce 2.5.2.dev1 (SDL 2.30.7, Python 3.12.0)
Platform:               Windows-11-10.0.22631-SP0
System:                 Windows
System Version:         10.0.22631
Processor:              AMD64 Family 23 Model 104 Stepping 1, AuthenticAMD      SSE2: Yes       AVX2: Yes       NEON: No
Architecture:           Bits: 64bit     Linkage: WindowsPE

Python:                 CPython 3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]
pygame version:         2.5.2.dev1
SDL versions:           Linked: 2.30.7  Compiled: 2.30.7
SDL Mixer versions:     Linked: 2.8.0   Compiled: 2.8.0
SDL Font versions:      Linked: 2.22.0  Compiled: 2.22.0
SDL Image versions:     Linked: 2.8.2   Compiled: 2.8.2
Freetype versions:      Linked: 2.11.1  Compiled: 2.11.1

Display Driver:         windows
Mixer Driver:           wasapi
MyreMylar commented 3 days ago

A minimal method of reproduction on windows to the new segfault (different to the old one):

import pygame

pygame.init()

pygame.display.set_mode([800, 600], flags=pygame.RESIZABLE | pygame.SCALED)
pygame.display.set_mode([800, 601], flags=pygame.RESIZABLE | pygame.SCALED)

All these elements seem necessary to trigger the segfault it has to be SCALED and RESIZABLE -> to SCALED and RESIZABLE and the windows has to change size.