Skip to content

Commit f604bed

Browse files
committed
set_at now take a long long for y instead of int
1 parent 787650b commit f604bed

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src_c/draw.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,8 +1425,12 @@ clip_line(SDL_Surface *surf, SDL_Rect surf_clip_rect, int *x1, int *y1,
14251425
}
14261426

14271427
static int
1428-
set_at(SDL_Surface *surf, SDL_Rect surf_clip_rect, int x, int y, Uint32 color)
1428+
set_at(SDL_Surface *surf, SDL_Rect surf_clip_rect, int x, long long y,
1429+
Uint32 color)
14291430
{
1431+
// y should be long long so that y * surf->pitch doesn't overflow the int
1432+
// bounds in the case of very large surfaces and drawing on the edge of
1433+
// them
14301434
Uint8 *pixels = (Uint8 *)surf->pixels;
14311435

14321436
if (x < surf_clip_rect.x || x >= surf_clip_rect.x + surf_clip_rect.w ||
@@ -1459,7 +1463,7 @@ static void
14591463
set_and_check_rect(SDL_Surface *surf, SDL_Rect surf_clip_rect, int x, int y,
14601464
Uint32 color, int *drawn_area)
14611465
{
1462-
if (set_at(surf, surf_clip_rect, x, y, color)) {
1466+
if (set_at(surf, surf_clip_rect, x, (long long)y, color)) {
14631467
add_pixel_to_drawn_list(x, y, drawn_area);
14641468
}
14651469
}
@@ -1788,7 +1792,7 @@ drawhorzlineclip(SDL_Surface *surf, SDL_Rect surf_clip_rect, Uint32 color,
17881792
}
17891793

17901794
if (x1 == x2) {
1791-
set_at(surf, surf_clip_rect, x1, y1, color);
1795+
set_at(surf, surf_clip_rect, x1, (long long)y1, color);
17921796
return;
17931797
}
17941798
drawhorzline(surf, color, x1, y1, x2);

test/draw_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,14 @@ def test_line_clipping_with_thickness(self):
18461846
"start={}, end={}".format(end_points[n], start_points[n]),
18471847
)
18481848

1849+
def test_line_draw_large_surf_regression(self):
1850+
"""Regression test for https://github.com/pygame-community/pygame-ce/issues/2961"""
1851+
surface = pygame.Surface((43371, 43371))
1852+
1853+
point1 = [30021, 37135]
1854+
point2 = [30022, 37136]
1855+
pygame.draw.line(surface, (255, 255, 255), point1, point2, 1)
1856+
18491857

18501858
### Lines Testing #############################################################
18511859

0 commit comments

Comments
 (0)