diff --git a/CHANGES b/CHANGES index 839ef04ec..890b57f2b 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,7 @@ Other fixes: - Libretro: Fix crash when using Game Boy codes (fixes mgba.io/i/2281) - Qt: Remove potentially deadlocking optimization - 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: - Wii: Add adjustable gyroscope settings (closes mgba.io/i/2245) diff --git a/src/platform/qt/AssetView.cpp b/src/platform/qt/AssetView.cpp index e686f91a9..66574b0df 100644 --- a/src/platform/qt/AssetView.cpp +++ b/src/platform/qt/AssetView.cpp @@ -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 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(mTileCacheGetVRAM(tileCache, t)), bits, objInfo.width * 8, x * 8, y * 8, objInfo.bits); } t += objInfo.stride - objInfo.width;