From b30905cc795b4bfaf977073a2fee37884e586e34 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 23 Apr 2025 14:42:33 -0700
Subject: [PATCH] Don't render a texture with an empty source rect
sdl2-compat specific fix for https://github.com/libsdl-org/sdl2-compat/issues/355
---
src/sdl2_compat.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 05625e3..12453ea 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -6275,6 +6275,10 @@ SDL_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *src
srcfrect.w = (float)srcrect->w;
srcfrect.h = (float)srcrect->h;
psrcfrect = &srcfrect;
+
+ if (srcrect->w == 0 || srcrect->h == 0) {
+ return 0;
+ }
}
if (dstrect) {
dstfrect.x = (float)dstrect->x;
@@ -6299,6 +6303,10 @@ SDL_RenderCopyF(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *sr
srcfrect.w = (float)srcrect->w;
srcfrect.h = (float)srcrect->h;
psrcfrect = &srcfrect;
+
+ if (srcrect->w == 0 || srcrect->h == 0) {
+ return 0;
+ }
}
retval = SDL3_RenderTexture(renderer, texture, psrcfrect, dstrect) ? 0 : -1;
return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);