pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

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

Open bilhox opened this issue 2 years ago • 11 comments

Environment:

  • Operating system : Windows 11
  • Python version : 3.11.4 / 3.12.0
  • SDL version : 2.26.5
  • PyGame version : 2.3.2 / 2.4.0.dev2

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

bilhox avatar Nov 19 '23 13:11 bilhox

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

Starbuck5 avatar Nov 22 '23 08:11 Starbuck5

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

No 🤔

bilhox avatar Nov 22 '23 12:11 bilhox

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?

Matiiss avatar Nov 22 '23 12:11 Matiiss

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

bilhox avatar Nov 22 '23 13:11 bilhox

Sending this GIF file to illustrate the problem : what_happened

bilhox avatar Dec 07 '23 08:12 bilhox

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)

MyreMylar avatar May 30 '24 15:05 MyreMylar

@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

bilhox avatar Sep 16 '24 19:09 bilhox

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.

MyreMylar avatar Sep 17 '24 16:09 MyreMylar

Cannot reproduce this issue in pygame-ce==2.5.5 but I'm on Ubuntu. @bilhox can you confirm if there is still an issue or segfault RN on windows?

ankith26 avatar Jun 14 '25 15:06 ankith26

None of the code snippets in this issue caused a segfault for me on windows

pygame-ce 2.5.5 (SDL 2.32.6, Python 3.13.3)
Platform:               Windows-11-10.0.26100-SP0
System:                 Windows
System Version:         10.0.26100
Processor:              AMD64 Family 25 Model 97 Stepping 2, AuthenticAMD       SSE2: Yes       AVX2: Yes       NEON: No
Architecture:           Bits: 64bit     Linkage: WindowsPE

Python:                 CPython 3.13.3 (tags/v3.13.3:6280bb5, Apr  8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
GIL Enabled:            True
pygame version:         2.5.5
SDL versions:           Linked: 2.32.6  Compiled: 2.32.6
SDL Mixer versions:     Linked: 2.8.1   Compiled: 2.8.1
SDL Font versions:      Linked: 2.24.0  Compiled: 2.24.0
SDL Image versions:     Linked: 2.8.8   Compiled: 2.8.8
Freetype versions:      Linked: 2.11.1  Compiled: 2.11.1

Display Driver:         windows
Mixer Driver:           wasapi

oddbookworm avatar Jun 14 '25 15:06 oddbookworm

Hello, the code snippet I originally provided in the issue still cause a segfault for me.

pygame-ce 2.5.5 (SDL 2.32.6, Python 3.13.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.13.0 (tags/v3.13.0:60403a5, Oct  7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)]
GIL Enabled:            True
pygame version:         2.5.5
SDL versions:           Linked: 2.32.6  Compiled: 2.32.6
SDL Mixer versions:     Linked: 2.8.1   Compiled: 2.8.1
SDL Font versions:      Linked: 2.24.0  Compiled: 2.24.0
SDL Image versions:     Linked: 2.8.8   Compiled: 2.8.8
Freetype versions:      Linked: 2.11.1  Compiled: 2.11.1

Display Driver:         windows
Mixer Driver:           wasapi

bilhox avatar Jun 14 '25 20:06 bilhox