Skip to content

Commit 38baab2

Browse files
committed
set_at now take a long long for y instead of int
1 parent c6c7d20 commit 38baab2

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src_c/draw.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,8 +1209,11 @@ clip_line(SDL_Surface *surf, int *x1, int *y1, int *x2, int *y2, int width,
12091209
}
12101210

12111211
static int
1212-
set_at(SDL_Surface *surf, int x, int y, Uint32 color)
1212+
set_at(SDL_Surface *surf, int x, long long y, Uint32 color)
12131213
{
1214+
// y should be long long so that y * surf->pitch doesn't overflow the int
1215+
// bounds in the case of very large surfaces and drawing on the edge of
1216+
// them
12141217
SDL_PixelFormat *format = surf->format;
12151218
Uint8 *pixels = (Uint8 *)surf->pixels;
12161219
Uint8 *byte_buf, rgb[4];
@@ -1250,7 +1253,7 @@ static void
12501253
set_and_check_rect(SDL_Surface *surf, int x, int y, Uint32 color,
12511254
int *drawn_area)
12521255
{
1253-
if (set_at(surf, x, y, color))
1256+
if (set_at(surf, x, (long long)y, color))
12541257
add_pixel_to_drawn_list(x, y, drawn_area);
12551258
}
12561259

@@ -1544,7 +1547,7 @@ drawhorzlineclip(SDL_Surface *surf, Uint32 color, int x1, int y1, int x2)
15441547
return;
15451548

15461549
if (x1 == x2) {
1547-
set_at(surf, x1, y1, color);
1550+
set_at(surf, x1, (long long)y1, color);
15481551
return;
15491552
}
15501553
drawhorzline(surf, color, x1, y1, x2);

test/draw_test.py

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

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

18511859
### Lines Testing #############################################################
18521860

0 commit comments

Comments
 (0)