Skip to content

Commit 1798994

Browse files
committed
Fixed SDL_BlitSurfaceTiledWithScale() with very small scale (thanks @bleeqer!)
1 parent 4a00aed commit 1798994

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/video/SDL_surface.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ bool SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, const SDL_Rect *srcrect, fl
14751475
CHECK_PARAM((src->flags & SDL_SURFACE_LOCKED) || (dst->flags & SDL_SURFACE_LOCKED)) {
14761476
return SDL_SetError("Surfaces must not be locked during blit");
14771477
}
1478-
CHECK_PARAM(scale <= 0.0f) {
1478+
CHECK_PARAM(scale < 0.0f) {
14791479
return SDL_InvalidParamError("scale");
14801480
}
14811481

@@ -1521,8 +1521,12 @@ bool SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, const SDL_Rect *srcrect, fl
15211521
SDL_InvalidateMap(&src->map);
15221522
}
15231523

1524-
int tile_width = (int)(r_src.w * scale);
1525-
int tile_height = (int)(r_src.h * scale);
1524+
int tile_width = (int)SDL_roundf(r_src.w * scale);
1525+
int tile_height = (int)SDL_roundf(r_src.h * scale);
1526+
if (tile_width <= 0 || tile_height <= 0) {
1527+
// Nothing to do
1528+
return true;
1529+
}
15261530
int rows = r_dst.h / tile_height;
15271531
int cols = r_dst.w / tile_width;
15281532
int remaining_dst_w = (r_dst.w - cols * tile_width);

test/testautomation_surface.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,13 @@ static int SDLCALL surface_testBlitTiled(void *arg)
442442
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
443443
}
444444

445+
/* Tiled blit - very small scale */
446+
{
447+
float tiny_scale = 0.01f;
448+
ret = SDL_BlitSurfaceTiledWithScale(face, NULL, tiny_scale, SDL_SCALEMODE_NEAREST, testSurface, NULL);
449+
SDLTest_AssertCheck(ret == true, "Expected SDL_BlitSurfaceTiledWithScale to succeed with very small scale: %f, got: %i", tiny_scale, ret);
450+
}
451+
445452
/* Clean up. */
446453
SDL_DestroySurface(face);
447454
SDL_DestroySurface(testSurface2x);

0 commit comments

Comments
 (0)