From 5605f85d84b00c6a3fe3f41d6ef086bc5e338dd3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 6 Sep 2025 10:07:09 -0700 Subject: [PATCH] Check the return value of SDL_SW_CopyYUVToRGB() --- src/render/SDL_render.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index 303d883b58..6adbe10f7d 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -2057,6 +2057,7 @@ static bool SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, { SDL_Texture *native = texture->native; SDL_Rect full_rect; + bool result = true; if (!SDL_SW_UpdateYUVTexture(texture->yuv, rect, pixels, pitch)) { return false; @@ -2076,8 +2077,7 @@ static bool SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, if (!SDL_LockTexture(native, rect, &native_pixels, &native_pitch)) { return false; } - SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, - rect->w, rect->h, native_pixels, native_pitch); + result = SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, native_pixels, native_pitch); SDL_UnlockTexture(native); } else { // Use a temporary buffer for updating @@ -2088,13 +2088,14 @@ static bool SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, if (!temp_pixels) { return false; } - SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, - rect->w, rect->h, temp_pixels, temp_pitch); - SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); + result = SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, temp_pixels, temp_pitch); + if (result) { + SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); + } SDL_free(temp_pixels); } } - return true; + return result; } #endif // SDL_HAVE_YUV @@ -2186,6 +2187,7 @@ static bool SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rec { SDL_Texture *native = texture->native; SDL_Rect full_rect; + bool result = true; if (!SDL_SW_UpdateYUVTexturePlanar(texture->yuv, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch)) { return false; @@ -2209,8 +2211,7 @@ static bool SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rec if (!SDL_LockTexture(native, rect, &native_pixels, &native_pitch)) { return false; } - SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, - rect->w, rect->h, native_pixels, native_pitch); + result = SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, native_pixels, native_pitch); SDL_UnlockTexture(native); } else { // Use a temporary buffer for updating @@ -2221,13 +2222,14 @@ static bool SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rec if (!temp_pixels) { return false; } - SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, - rect->w, rect->h, temp_pixels, temp_pitch); - SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); + result = SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, temp_pixels, temp_pitch); + if (result) { + SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); + } SDL_free(temp_pixels); } } - return true; + return result; } static bool SDL_UpdateTextureNVPlanar(SDL_Texture *texture, const SDL_Rect *rect, @@ -2236,6 +2238,7 @@ static bool SDL_UpdateTextureNVPlanar(SDL_Texture *texture, const SDL_Rect *rect { SDL_Texture *native = texture->native; SDL_Rect full_rect; + bool result = true; if (!SDL_SW_UpdateNVTexturePlanar(texture->yuv, rect, Yplane, Ypitch, UVplane, UVpitch)) { return false; @@ -2259,8 +2262,7 @@ static bool SDL_UpdateTextureNVPlanar(SDL_Texture *texture, const SDL_Rect *rect if (!SDL_LockTexture(native, rect, &native_pixels, &native_pitch)) { return false; } - SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, - rect->w, rect->h, native_pixels, native_pitch); + result = SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, native_pixels, native_pitch); SDL_UnlockTexture(native); } else { // Use a temporary buffer for updating @@ -2271,13 +2273,14 @@ static bool SDL_UpdateTextureNVPlanar(SDL_Texture *texture, const SDL_Rect *rect if (!temp_pixels) { return false; } - SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, - rect->w, rect->h, temp_pixels, temp_pitch); - SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); + result = SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, temp_pixels, temp_pitch); + if (result) { + SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); + } SDL_free(temp_pixels); } } - return true; + return result; } #endif // SDL_HAVE_YUV