From 151d7c5736aaf9d8719b292a4b22b0d66c086e14 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 13 Jan 2025 22:03:36 -0600 Subject: [PATCH] [nostalgia/core/gba] Fix partial tilesheet loading overrun --- src/nostalgia/modules/core/src/gba/gfx.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nostalgia/modules/core/src/gba/gfx.cpp b/src/nostalgia/modules/core/src/gba/gfx.cpp index 59e25287..3d58ce57 100644 --- a/src/nostalgia/modules/core/src/gba/gfx.cpp +++ b/src/nostalgia/modules/core/src/gba/gfx.cpp @@ -99,10 +99,10 @@ ox::Error loadBgTileSheet( size_t const tileCnt) noexcept { size_t const bppMod = ts.bpp == 4; size_t const bytesPerTile = PixelsPerTile >> bppMod; - auto const pixCnt = tileCnt * bytesPerTile; + auto const cnt = (tileCnt * bytesPerTile) / 2; auto const srcPxIdx = srcTileIdx * bytesPerTile; auto const dstPxIdx = (dstTileIdx * bytesPerTile) / 2; - for (size_t i = 0; i < pixCnt; ++i) { + for (size_t i = 0; i < cnt; ++i) { auto const srcIdx = srcPxIdx + i * 2; auto const p1 = static_cast(ts.pixels[srcIdx]); auto const p2 = static_cast(ts.pixels[srcIdx + 1]);