From de81b706c4b4847daeb94fce3970171c6853535a Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 11 Mar 2020 06:48:11 -0700 Subject: [PATCH] PPGe: Clear unused parts of text image buffers. Prevents artifacts when the RAM previously had other data in it. --- Core/Util/PPGeDraw.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Core/Util/PPGeDraw.cpp b/Core/Util/PPGeDraw.cpp index 354d77ab86..bf64fb1725 100644 --- a/Core/Util/PPGeDraw.cpp +++ b/Core/Util/PPGeDraw.cpp @@ -828,7 +828,7 @@ static PPGeTextDrawerImage PPGeGetTextImage(const char *text, int align, float s textDrawer->DrawStringBitmapRect(bitmapData, im.entry, Draw::DataFormat::R8_UNORM, cleaned.c_str(), b, tdalign); int bufwBytes = ((im.entry.bmWidth + 31) / 32) * 16; - u32 sz = bufwBytes * im.entry.bmHeight; + u32 sz = bufwBytes * (im.entry.bmHeight + 1); u32 origSz = sz; im.ptr = __PPGeDoAlloc(sz, true, "PPGeText"); @@ -836,15 +836,20 @@ static PPGeTextDrawerImage PPGeGetTextImage(const char *text, int align, float s bitmapData.resize(bitmapData.size() + 1); if (im.ptr) { + int wBytes = (im.entry.bmWidth + 1) / 2; u8 *ramPtr = (u8 *)Memory::GetPointer(im.ptr); for (int y = 0; y < im.entry.bmHeight; ++y) { - for (int x = 0; x < (im.entry.bmWidth + 1) / 2; ++x) { + for (int x = 0; x < wBytes; ++x) { uint8_t c1 = bitmapData[y * im.entry.bmWidth + x * 2]; uint8_t c2 = bitmapData[y * im.entry.bmWidth + x * 2 + 1]; // Convert this to 4-bit palette values. ramPtr[y * bufwBytes + x] = (c2 & 0xF0) | (c1 >> 4); } + if (bufwBytes != wBytes) { + memset(ramPtr + y * bufwBytes + wBytes, 0, bufwBytes - wBytes); + } } + memset(ramPtr + im.entry.bmHeight * bufwBytes, 0, bufwBytes + sz - origSz); } im.entry.lastUsedFrame = gpuStats.numFlips;