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
825 stars 131 forks source link

Fatal python error when blitting onto large surfaces #3055

Open PreciousFood opened 1 month ago

PreciousFood commented 1 month ago

Environment:

Platform:               Windows-10-10.0.22631-SP0
System:                 Windows
System Version:         10.0.22631
Processor:              Intel64 Family 6 Model 170 Stepping 4, GenuineIntel
Architecture:           Bits: 64bit     Linkage: WindowsPE

Python:                 CPython 3.11.9 (tags/v3.11.9:de54cf5, Apr  2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)]
pygame version:         2.5.0
SDL versions:           Linked: 2.30.3  Compiled: 2.30.3
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

Current behavior:

A fatal python error occurs when blitting a surface onto a large coordinate on a large surface.

The provided code is a stripped down version of the project I was working on. When I was testing it I decided to see what would happen when the surface got large. My computer bluescreened with a VIDEO TDR FAILURE. This only happened the first time. I have only gotten the fatal python error since then.

It is possible that this is connected to #2288 although that claims to be fixed in SDL 2.30.x Also might be connected to #2961 as both have to do with drawing on large surfaces

Expected behavior:

No error/crash or at the verry least an error explaining that the operation is not possible due to whatever applicable limitations

Steps to reproduce:

Run the following...

# pygame-ce 2.5.0 (SDL 2.30.3, Python 3.11.9)
import pygame

pygame.init()

pygame.print_debug_info()

a = pygame.Surface((40_000, 40_000))
b = pygame.Surface((100, 100))

a.blit(b, (20_000, 20_000))  # the problem

Result...

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

Current thread 0x00005ce8 (most recent call first):
  File "c:\Users\XXXXXXXX\fail.py", line 15 in <module>

Extension modules: 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, pygame.system, pygame._freetype (total: 27)
bilhox commented 1 month ago

gdb stacktrace :

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
Downloading source file /usr/src/libsdl2-2.30.0+dfsg-1build3/src/video/SDL_blit_copy.c
SDL_memcpySSE (len=<optimized out>, src=0x1112560 "",
    dst=0x7ffdf94508a0 <error: Cannot access memory at address 0x7ffdf94508a0>)
    at /usr/src/libsdl2-2.30.0+dfsg-1build3/src/video/SDL_blit_copy.c:41
41              _mm_stream_ps((float *)(dst + 16), values[1]);

Specific line in surface.c :

3895|        result = SDL_BlitSurface(src, srcrect, dst, dstrect);