From 41f1c83caae6a09c9a3bddc92bbb5408b1037122 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 15 Aug 2024 07:38:43 -0700
Subject: [PATCH] If scaling fails, fall back to the closest image available in
SDL_GetSurfaceImage()
---
src/video/SDL_surface.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c
index 49c0c7b1170ce..e2a03d0b0a29a 100644
--- a/src/video/SDL_surface.c
+++ b/src/video/SDL_surface.c
@@ -555,7 +555,9 @@ SDL_Surface *SDL_GetSurfaceImage(SDL_Surface *surface, float display_scale)
}
scaled = next_scaled;
if (!scaled) {
- return NULL;
+ // Failure, fall back to the closest surface
+ ++closest->refcount;
+ return closest;
}
} while (scaled->w != desired_w || scaled->h != desired_h);