From afb3c834a77f7da8a27afc5fd2926792e0227f81 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 21 Apr 2020 14:54:29 +0100 Subject: [PATCH] Do not draw sprites with backwards/empty RECTs Previously, each backend had to guard against it, which is messy, results in duplication, and leaves new backends open to the risk of not guarding against it (the Wii U GX2 renderer didn't). --- src/Draw.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Draw.cpp b/src/Draw.cpp index 16742d2b..8fbbdcfc 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -419,6 +419,10 @@ void BackupSurface(SurfaceID surf_no, const RECT *rect) scaled_rect.right = rect->right * magnification; scaled_rect.bottom = rect->bottom * magnification; + // Do not draw invalid RECTs + if (rcWork->right <= rcWork->left || rcWork->bottom <= rcWork->top) + return; + RenderBackend_Blit(framebuffer, &scaled_rect, surf[surf_no], scaled_rect.left, scaled_rect.top, FALSE); } @@ -454,6 +458,10 @@ void PutBitmap3(const RECT *rcView, int x, int y, const RECT *rect, SurfaceID su rcWork.right *= magnification; rcWork.bottom *= magnification; + // Do not draw invalid RECTs + if (rcWork->right <= rcWork->left || rcWork->bottom <= rcWork->top) + return; + RenderBackend_Blit(surf[surf_no], &rcWork, framebuffer, x * magnification, y * magnification, TRUE); } @@ -489,6 +497,10 @@ void PutBitmap4(const RECT *rcView, int x, int y, const RECT *rect, SurfaceID su rcWork.right *= magnification; rcWork.bottom *= magnification; + // Do not draw invalid RECTs + if (rcWork->right <= rcWork->left || rcWork->bottom <= rcWork->top) + return; + RenderBackend_Blit(surf[surf_no], &rcWork, framebuffer, x * magnification, y * magnification, FALSE); } @@ -501,6 +513,10 @@ void Surface2Surface(int x, int y, const RECT *rect, int to, int from) rcWork.right = rect->right * magnification; rcWork.bottom = rect->bottom * magnification; + // Do not draw invalid RECTs + if (rcWork->right <= rcWork->left || rcWork->bottom <= rcWork->top) + return; + RenderBackend_Blit(surf[from], &rcWork, surf[to], x * magnification, y * magnification, TRUE); } @@ -522,6 +538,10 @@ void CortBox(const RECT *rect, unsigned long col) const unsigned char green = (col >> 8) & 0xFF; const unsigned char blue = (col >> 16) & 0xFF; + // Do not draw invalid RECTs + if (dst_rect->right <= dst_rect->left || dst_rect->bottom <= dst_rect->top) + return; + RenderBackend_ColourFill(framebuffer, &dst_rect, red, green, blue); } @@ -539,6 +559,10 @@ void CortBox2(const RECT *rect, unsigned long col, SurfaceID surf_no) const unsigned char green = (col >> 8) & 0xFF; const unsigned char blue = (col >> 16) & 0xFF; + // Do not draw invalid RECTs + if (dst_rect->right <= dst_rect->left || dst_rect->bottom <= dst_rect->top) + return; + RenderBackend_ColourFill(surf[surf_no], &dst_rect, red, green, blue); }