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

Fix display.set_mode segfault after resizing

Open MightyJosip opened this issue 5 months ago • 3 comments
trafficstars

This should fix the following code that segfaults

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

This also fixes #2571

TLDR: Changing size of the window invalidates surface returned by SDL_GetWindowSurface() as explained in https://wiki.libsdl.org/SDL2/SDL_GetWindowSurface, so this commit makes sure the module always has the reference to the right SDL_Surface (hopefully). There are other possible fixes for this, but this one to me looks the most elegant (unless we rewrite the entire module/function).

And the long explanation is available in our discord server https://discord.com/channels/772505616680878080/772940667231928360/1383591122101604402

Also, if someone knows another place in our code when the resizing could happen, make sure to notify me to add this new helper function there as well

EDIT: Looks like there is a memory leak with this change, will need to check if it happens without it

EDIT 2: I am pretty sure that the memory leak happens because of #3502

MightyJosip avatar Jun 15 '25 10:06 MightyJosip