Qt: Fix sprite compositing when sprite tiles go out of bounds (fixes #2348)

This commit is contained in:
Vicki Pfau 2021-11-09 15:53:32 -08:00
parent 71b616a9c2
commit 1b71a64c51
2 changed files with 5 additions and 2 deletions

View File

@ -31,6 +31,7 @@ Other fixes:
- GBA: Fix maximum tile ID in caching for 256-color modes
- Libretro: Fix crash when using Game Boy codes (fixes mgba.io/i/2281)
- Qt: Fix corrupted savestate and fatal error text
- Qt: Fix sprite compositing when sprite tiles go out of bounds (fixes mgba.io/i/2348)
Misc:
- Core: Suspend runloop when a core crashes
- GBA I/O: Update KEYINPUT in internal I/O memory (fixes mgba.io/i/2235)

View File

@ -131,6 +131,7 @@ QImage AssetView::compositeMap(int map, mMapCacheEntry* mapStatus) {
QImage AssetView::compositeObj(const ObjInfo& objInfo) {
mTileCache* tileCache = mTileCacheSetGetPointer(&m_cacheSet->tiles, objInfo.paletteSet);
unsigned maxTiles = mTileCacheSystemInfoGetMaxTiles(tileCache->sysConfig);
const color_t* rawPalette = mTileCacheGetPalette(tileCache, objInfo.paletteId);
unsigned colors = 1 << objInfo.bits;
QVector<QRgb> palette;
@ -142,10 +143,11 @@ QImage AssetView::compositeObj(const ObjInfo& objInfo) {
QImage image = QImage(QSize(objInfo.width * 8, objInfo.height * 8), QImage::Format_Indexed8);
image.setColorTable(palette);
image.fill(0);
uchar* bits = image.bits();
unsigned t = objInfo.tile;
for (unsigned y = 0; y < objInfo.height; ++y) {
for (unsigned x = 0; x < objInfo.width; ++x, ++t) {
for (unsigned y = 0; y < objInfo.height && t < maxTiles; ++y) {
for (unsigned x = 0; x < objInfo.width && t < maxTiles; ++x, ++t) {
compositeTile(static_cast<const void*>(mTileCacheGetVRAM(tileCache, t)), bits, objInfo.width * 8, x * 8, y * 8, objInfo.bits);
}
t += objInfo.stride - objInfo.width;