Skip to content

Commit 79a1c58

Browse files
authored
Merge pull request #2980 from itzpr3d4t0r/fix-premul-alpha-ip
Ensure `.premul_alpha_ip()` works with zero sized Surfaces
2 parents 13d3e70 + 88ac7a1 commit 79a1c58

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src_c/surface.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,8 +3134,10 @@ surf_premul_alpha_ip(pgSurfaceObject *self, PyObject *_null)
31343134
SDL_Surface *surf = pgSurface_AsSurface(self);
31353135
SURF_INIT_CHECK(surf)
31363136

3137-
if (!surf->w || !surf->h)
3138-
Py_RETURN_NONE;
3137+
if (!surf->w || !surf->h) {
3138+
Py_INCREF(self);
3139+
return (PyObject *)self;
3140+
}
31393141

31403142
pgSurface_Prep(self);
31413143

test/surface_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4108,6 +4108,11 @@ def test_surface_premul_alpha_ip(self):
41084108
),
41094109
)
41104110

4111+
for size in [(0, 0), (1, 0), (0, 1), (10, 10)]:
4112+
surf = pygame.Surface(size, pygame.SRCALPHA, 32)
4113+
surf.fill((32, 44, 4, 123))
4114+
self.assertIs(surf, surf.premul_alpha_ip())
4115+
41114116

41124117
class SurfaceSelfBlitTest(unittest.TestCase):
41134118
"""Blit to self tests.

0 commit comments

Comments
 (0)