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

Seg fault in pygame._sdl2.Renderer.to_surface() when pygame._sdl2.Renderer.logical_size has been set

Open rethanon opened this issue 1 year ago • 0 comments
trafficstars

Environment:

Platform: Windows-11 OS build 22631.3958 System: Windows System Version: 10.0.22631 Processor: AMD Ryzen9 5900X

Python: Python 3.12.2 pygame-ce version: 2.5.0 SDL versions: 2.30.3

Display Driver: windows

Current behaviour:

When using pygame._sdl2.Renderer.to_surface(), if the application window is fullscreen(desktop=True) and pygame._sdl2.Renderer.logical_size has been set., this results in a segmentation fault. If the application is windowed then the segmentation fault does not occur.

Expected behaviour:

Segmentation fault is not experienced and program continues normally.

Screenshots

image

Steps to reproduce:

  1. Create a window using pygame.Window()
  2. Create a renderer using pygame._sdl2.Renderer()
  3. Set a logical size for the renderer using pygame._sdl2.Renderer.logical_size()
  4. Set the window to fullscreen using desktop resolution using pygame.Window.set_fullscreen(desktop=True)
  5. Try to take a copy of the renderer and output to a surface using pygame._sdl2.Renderer.to_surface()

Test code

Use the 'Space' key to toggle between windowed and fullscreen. Use the 'R' key to perform the renderer copy to a surface.

import pygame
import pygame._sdl2 as sdl2

pygame.init()

WINDOW = pygame.Window("Test Window", (800, 600))
RENDERER = sdl2.Renderer(WINDOW)
RENDERER.draw_color = "blue"
RENDERER.logical_size = (800, 600)

fullscreen = False

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.WINDOWCLOSE:
            running = False
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                running = False
            elif event.key == pygame.K_r:
                new_surface = RENDERER.to_surface()
            elif event.key == pygame.K_SPACE:
                if fullscreen:
                    WINDOW.set_windowed()
                else:
                    WINDOW.set_fullscreen(desktop=True)
                fullscreen = not fullscreen

    RENDERER.clear()
    RENDERER.present()

Stack trace/error output/other error logs

Fatal Python error: pygame_parachute: (pygame parachute) Segmentation Fault
Python runtime state: initialized

Current thread 0x00007f20 (most recent call first):
  File "c:\Users\retha\Desktop\sdl2_seg_fault.py", line 22 in <module>

Extension modules: _wmi, pygame.base, pygame.constants, pygame.rect, pygame.rwobject, pygame.surflock, pygame.bufferproxy, pygame.math, pygame.surface, pygame.window, pygame.display, pygame.draw, pygame.joystick, pygame.event, pygame.imageext, pygame.image, pygame.key, pygame.mouse, pygame.time, pygame.mask, pygame.pixelcopy, pygame.transform, pygame.font, pygame.mixer_music, pygame.mixer, pygame.scrap, numpy.core._multiarray_umath, numpy.core._multiarray_tests, numpy.linalg._umath_linalg, numpy.fft._pocketfft_internal, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._mt19937, numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64, numpy.random._sfc64, numpy.random._generator, pygame.system, pygame._sdl2.sdl2, pygame._sdl2.audio, pygame._sdl2.video, pygame._freetype (total: 44)

rethanon avatar Aug 02 '24 23:08 rethanon