Loading pkgs/development/python-modules/pygame/0001-Use-SDL_AllocFormat-instead-of-creating-it-manually.patch 0 → 100644 +53 −0 Original line number Diff line number Diff line From bc1a52062adfacc94661883157dd4ef58e00e031 Mon Sep 17 00:00:00 2001 From: Marcin Serwin <marcin@serwin.dev> Date: Sat, 8 Nov 2025 14:48:04 +0100 Subject: [PATCH] Use SDL_AllocFormat instead of creating it manually According to the docs, `SDL_PixelFormat` is a read-only structure. Creating it manually leaves out some important fields like `format` and `next` pointer to be undefined. Signed-off-by: Marcin Serwin <marcin@serwin.dev> --- src_c/surface.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src_c/surface.c b/src_c/surface.c index 958ce43f..9be3d8fb 100644 --- a/src_c/surface.c +++ b/src_c/surface.c @@ -3730,24 +3730,13 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj, } else { SDL_PixelFormat *fmt = src->format; - SDL_PixelFormat newfmt; - - newfmt.palette = 0; /* Set NULL (or SDL gets confused) */ - newfmt.BitsPerPixel = fmt->BitsPerPixel; - newfmt.BytesPerPixel = fmt->BytesPerPixel; - newfmt.Amask = 0; - newfmt.Rmask = fmt->Rmask; - newfmt.Gmask = fmt->Gmask; - newfmt.Bmask = fmt->Bmask; - newfmt.Ashift = 0; - newfmt.Rshift = fmt->Rshift; - newfmt.Gshift = fmt->Gshift; - newfmt.Bshift = fmt->Bshift; - newfmt.Aloss = 0; - newfmt.Rloss = fmt->Rloss; - newfmt.Gloss = fmt->Gloss; - newfmt.Bloss = fmt->Bloss; - src = SDL_ConvertSurface(src, &newfmt, 0); + SDL_PixelFormat *newfmt = + SDL_AllocFormat(SDL_MasksToPixelFormatEnum( + fmt->BitsPerPixel, fmt->Rmask, fmt->Gmask, fmt->Bmask, 0)); + + src = SDL_ConvertSurface(src, newfmt, 0); + + SDL_FreeFormat(newfmt); if (src) { result = SDL_BlitSurface(src, srcrect, dst, dstrect); SDL_FreeSurface(src); -- 2.51.0 pkgs/development/python-modules/pygame/adapt-to-sdl3-format-message.patchdeleted 100644 → 0 +0 −14 Original line number Diff line number Diff line diff --git a/src_c/surface.c b/src_c/surface.c index ee9991fb..32c007bd 100644 --- a/src_c/surface.c +++ b/src_c/surface.c @@ -733,7 +733,8 @@ _raise_create_surface_error(void) { const char *msg = SDL_GetError(); - if (strcmp(msg, "Unknown pixel format") == 0) + if (strcmp(msg, "Unknown pixel format") == 0 || + strcmp(msg, "Parameter 'format' is invalid") == 0) return RAISE(PyExc_ValueError, "Invalid mask values"); return RAISE(pgExc_SDLError, msg); } pkgs/development/python-modules/pygame/default.nix +5 −3 Original line number Diff line number Diff line Loading @@ -62,14 +62,16 @@ buildPythonPackage rec { # mixer queue test returns busy queue when it shouldn't ./skip-mixer-test.patch # https://github.com/libsdl-org/sdl2-compat/issues/476 # Can be removed with the next SDL3 bump. ./skip-rle-tests.patch # https://github.com/libsdl-org/sdl2-compat/issues/489 ./adapt-to-sdl3-format-message.patch # https://github.com/pygame/pygame/pull/4497 ./0001-Use-SDL_HasSurfaceRLE-when-available.patch ./0002-Don-t-assume-that-touch-devices-support-get_num_fing.patch # https://github.com/pygame/pygame/pull/4651 ./0001-Use-SDL_AllocFormat-instead-of-creating-it-manually.patch ]; postPatch = '' Loading pkgs/development/python-modules/pygame/skip-rle-tests.patch +11 −11 Original line number Diff line number Diff line diff --git a/test/surface_test.py b/test/surface_test.py index 4e4b5d4..ffc7ffb 100644 index b1147d27..c7ba2928 100644 --- a/test/surface_test.py +++ b/test/surface_test.py @@ -375,6 +375,7 @@ class SurfaceTypeTest(unittest.TestCase): self.assertTrue(s1.get_flags() & pygame.RLEACCELOK) self.assertTrue(not s2.get_flags() & pygame.RLEACCELOK) + @unittest.skipIf(True, "https://github.com/libsdl-org/sdl2-compat/issues/476") def test_solarwolf_rle_usage(self): """Test for error/crash when calling set_colorkey() followed by convert twice in succession. Code originally taken @@ -403,6 +404,7 @@ class SurfaceTypeTest(unittest.TestCase): @@ -346,6 +346,7 @@ class SurfaceTypeTest(unittest.TestCase): finally: pygame.display.quit() + @unittest.skipIf(True, "https://github.com/libsdl-org/sdl2-compat/issues/476") + @unittest.skipIf(True, "https://github.com/libsdl-org/SDL/pull/14429") def test_solarwolf_rle_usage_2(self): """Test for RLE status after setting alpha""" @@ -377,6 +378,7 @@ class SurfaceTypeTest(unittest.TestCase): finally: pygame.display.quit() + @unittest.skipIf(True, "https://github.com/libsdl-org/SDL/issues/14424") def test_set_alpha__set_colorkey_rle(self): pygame.display.init() try: Loading
pkgs/development/python-modules/pygame/0001-Use-SDL_AllocFormat-instead-of-creating-it-manually.patch 0 → 100644 +53 −0 Original line number Diff line number Diff line From bc1a52062adfacc94661883157dd4ef58e00e031 Mon Sep 17 00:00:00 2001 From: Marcin Serwin <marcin@serwin.dev> Date: Sat, 8 Nov 2025 14:48:04 +0100 Subject: [PATCH] Use SDL_AllocFormat instead of creating it manually According to the docs, `SDL_PixelFormat` is a read-only structure. Creating it manually leaves out some important fields like `format` and `next` pointer to be undefined. Signed-off-by: Marcin Serwin <marcin@serwin.dev> --- src_c/surface.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src_c/surface.c b/src_c/surface.c index 958ce43f..9be3d8fb 100644 --- a/src_c/surface.c +++ b/src_c/surface.c @@ -3730,24 +3730,13 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj, } else { SDL_PixelFormat *fmt = src->format; - SDL_PixelFormat newfmt; - - newfmt.palette = 0; /* Set NULL (or SDL gets confused) */ - newfmt.BitsPerPixel = fmt->BitsPerPixel; - newfmt.BytesPerPixel = fmt->BytesPerPixel; - newfmt.Amask = 0; - newfmt.Rmask = fmt->Rmask; - newfmt.Gmask = fmt->Gmask; - newfmt.Bmask = fmt->Bmask; - newfmt.Ashift = 0; - newfmt.Rshift = fmt->Rshift; - newfmt.Gshift = fmt->Gshift; - newfmt.Bshift = fmt->Bshift; - newfmt.Aloss = 0; - newfmt.Rloss = fmt->Rloss; - newfmt.Gloss = fmt->Gloss; - newfmt.Bloss = fmt->Bloss; - src = SDL_ConvertSurface(src, &newfmt, 0); + SDL_PixelFormat *newfmt = + SDL_AllocFormat(SDL_MasksToPixelFormatEnum( + fmt->BitsPerPixel, fmt->Rmask, fmt->Gmask, fmt->Bmask, 0)); + + src = SDL_ConvertSurface(src, newfmt, 0); + + SDL_FreeFormat(newfmt); if (src) { result = SDL_BlitSurface(src, srcrect, dst, dstrect); SDL_FreeSurface(src); -- 2.51.0
pkgs/development/python-modules/pygame/adapt-to-sdl3-format-message.patchdeleted 100644 → 0 +0 −14 Original line number Diff line number Diff line diff --git a/src_c/surface.c b/src_c/surface.c index ee9991fb..32c007bd 100644 --- a/src_c/surface.c +++ b/src_c/surface.c @@ -733,7 +733,8 @@ _raise_create_surface_error(void) { const char *msg = SDL_GetError(); - if (strcmp(msg, "Unknown pixel format") == 0) + if (strcmp(msg, "Unknown pixel format") == 0 || + strcmp(msg, "Parameter 'format' is invalid") == 0) return RAISE(PyExc_ValueError, "Invalid mask values"); return RAISE(pgExc_SDLError, msg); }
pkgs/development/python-modules/pygame/default.nix +5 −3 Original line number Diff line number Diff line Loading @@ -62,14 +62,16 @@ buildPythonPackage rec { # mixer queue test returns busy queue when it shouldn't ./skip-mixer-test.patch # https://github.com/libsdl-org/sdl2-compat/issues/476 # Can be removed with the next SDL3 bump. ./skip-rle-tests.patch # https://github.com/libsdl-org/sdl2-compat/issues/489 ./adapt-to-sdl3-format-message.patch # https://github.com/pygame/pygame/pull/4497 ./0001-Use-SDL_HasSurfaceRLE-when-available.patch ./0002-Don-t-assume-that-touch-devices-support-get_num_fing.patch # https://github.com/pygame/pygame/pull/4651 ./0001-Use-SDL_AllocFormat-instead-of-creating-it-manually.patch ]; postPatch = '' Loading
pkgs/development/python-modules/pygame/skip-rle-tests.patch +11 −11 Original line number Diff line number Diff line diff --git a/test/surface_test.py b/test/surface_test.py index 4e4b5d4..ffc7ffb 100644 index b1147d27..c7ba2928 100644 --- a/test/surface_test.py +++ b/test/surface_test.py @@ -375,6 +375,7 @@ class SurfaceTypeTest(unittest.TestCase): self.assertTrue(s1.get_flags() & pygame.RLEACCELOK) self.assertTrue(not s2.get_flags() & pygame.RLEACCELOK) + @unittest.skipIf(True, "https://github.com/libsdl-org/sdl2-compat/issues/476") def test_solarwolf_rle_usage(self): """Test for error/crash when calling set_colorkey() followed by convert twice in succession. Code originally taken @@ -403,6 +404,7 @@ class SurfaceTypeTest(unittest.TestCase): @@ -346,6 +346,7 @@ class SurfaceTypeTest(unittest.TestCase): finally: pygame.display.quit() + @unittest.skipIf(True, "https://github.com/libsdl-org/sdl2-compat/issues/476") + @unittest.skipIf(True, "https://github.com/libsdl-org/SDL/pull/14429") def test_solarwolf_rle_usage_2(self): """Test for RLE status after setting alpha""" @@ -377,6 +378,7 @@ class SurfaceTypeTest(unittest.TestCase): finally: pygame.display.quit() + @unittest.skipIf(True, "https://github.com/libsdl-org/SDL/issues/14424") def test_set_alpha__set_colorkey_rle(self): pygame.display.init() try: