Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling pygame.display.set_mode a second time crashes with SCALED flag if it hasn't been called with it the first time. #2737

Open
u8slvn opened this issue Mar 4, 2024 · 6 comments
Labels
bug Not working as intended

Comments

@u8slvn
Copy link

u8slvn commented Mar 4, 2024

Environment:

  • Operating system: Windows 10
  • Python version: 3.11.4
  • SDL version: 2.28.5
  • pygame-ce version: 2.4.1

Current behavior:

When the method pygame.display.set_mode is called a second time with SCALED flag and hasn't been called the first time with SCALED flag, pygame crash with the following error:

pygame.error: failed to create renderer

The error happens only when set_mode is called with SCALED flag and if it hasn't been set with it before.

Expected behavior:

This seems to happen only since 2.4.0, I tested it with 2.3.2 and it works properly.

Steps to reproduce:

  1. Call set_mode without SCALED flag.
  2. Call set_mode a second time with SCALED flag makes pygame crash.

Or:

  1. Call set_mode with SCALED flag.
  2. Call set_mode a second time without it, this will work as intended.
  3. Call set_mode a third time with SCALED flag, then it crashes.

Test code

Just press SPACE key to switch mode.

import pygame

pygame.init()

screen = pygame.display.set_mode((500, 500), pygame.RESIZABLE)

running = True
fullscreen = False

while running:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE:
                fullscreen = not fullscreen
                if fullscreen is True:
                    screen = pygame.display.set_mode((500, 500), pygame.FULLSCREEN | pygame.SCALED)
                else:
                    screen = pygame.display.set_mode((500, 500), pygame.RESIZABLE)

        if event.type == pygame.QUIT:
            running = False

    screen.fill((255, 255, 255))
    pygame.draw.circle(screen, (0, 255, 0), (250, 250), 75)
    pygame.display.flip()

pygame.quit()
@u8slvn u8slvn added the bug Not working as intended label Mar 4, 2024
@ankith26
Copy link
Member

ankith26 commented Mar 6, 2024

Thanks for the bug report.

I cannot seem to reproduce this on Ubuntu, perhaps this is a windows only issue

@Starbuck5
Copy link
Member

This seems like the same problem as #2571 and #2376

@Starbuck5
Copy link
Member

If you're trying to run code that switches between SCALED and not-scaled, I think it would work to quit and re-initialize the video system while doing it. pygame.display.quit() and pygame.display.init(). Haven't tested though.

I cannot seem to reproduce this on Ubuntu, perhaps this is a windows only issue

This is in a whole stream of renderer semantics issues, and all the earliest reports were on Linux, so that's surprising. Are you using an old system SDL? It's an SDL version thing.

@u8slvn
Copy link
Author

u8slvn commented Mar 7, 2024

I think it would work to quit and re-initialize the video system while doing it. pygame.display.quit() and pygame.display.init().

I just tested it and it does the trick! Thks!

@ankith26
Copy link
Member

ankith26 commented Mar 7, 2024

This is in a whole stream of renderer semantics issues, and all the earliest reports were on Linux, so that's surprising. Are you using an old system SDL? It's an SDL version thing.

No, I'm using pip installed pygame-ce 2.4.1 (SDL 2.28.5, Python 3.11.6)

@MyreMylar
Copy link
Member

MyreMylar commented May 30, 2024

simplest repro:

import pygame

pygame.init()

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not working as intended
Projects
None yet
Development

No branches or pull requests

4 participants