diff --git a/CHANGES b/CHANGES index d55b8a446..2953c29e5 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,7 @@ Other fixes: - GBA: Fix out of bounds ROM accesses on patched ROMs smaller than 32 MiB - Qt: Fix infrequent deadlock when using sync to video - Qt: Fix applying savetype-only overrides + - Qt: Fix crash in sprite view for partially out-of-bounds sprites (fixes mgba.io/i/2165) - Util: Fix loading UPS patches that affect the last byte of the file Misc: - Core: Suspend runloop when a core crashes diff --git a/src/platform/qt/ObjView.cpp b/src/platform/qt/ObjView.cpp index ee1751e9e..0a67f69ce 100644 --- a/src/platform/qt/ObjView.cpp +++ b/src/platform/qt/ObjView.cpp @@ -131,15 +131,19 @@ void ObjView::updateTilesGBA(bool force) { m_objInfo = newInfo; m_tileOffset = newInfo.tile; mTileCache* tileCache = mTileCacheSetGetPointer(&m_cacheSet->tiles, newInfo.paletteSet); - + unsigned maxTiles = mTileCacheSystemInfoGetMaxTiles(tileCache->sysConfig); int i = 0; for (unsigned y = 0; y < newInfo.height; ++y) { for (unsigned x = 0; x < newInfo.width; ++x, ++i, ++tile, ++tileBase) { - const color_t* data = mTileCacheGetTileIfDirty(tileCache, &m_tileStatus[16 * tileBase], tile, newInfo.paletteId); - if (data) { - m_ui.tiles->setTile(i, data); - } else if (force) { - m_ui.tiles->setTile(i, mTileCacheGetTile(tileCache, tile, newInfo.paletteId)); + if (tile < maxTiles) { + const color_t* data = mTileCacheGetTileIfDirty(tileCache, &m_tileStatus[16 * tileBase], tile, newInfo.paletteId); + if (data) { + m_ui.tiles->setTile(i, data); + } else if (force) { + m_ui.tiles->setTile(i, mTileCacheGetTile(tileCache, tile, newInfo.paletteId)); + } + } else { + m_ui.tiles->clearTile(i); } } tile += newInfo.stride - newInfo.width; diff --git a/src/platform/qt/TilePainter.cpp b/src/platform/qt/TilePainter.cpp index 4e0490f36..9a1238699 100644 --- a/src/platform/qt/TilePainter.cpp +++ b/src/platform/qt/TilePainter.cpp @@ -44,6 +44,16 @@ void TilePainter::mousePressEvent(QMouseEvent* event) { emit indexPressed(y * (width() / m_size) + x); } +void TilePainter::clearTile(int index) { + QPainter painter(&m_backing); + int w = width() / m_size; + int x = index % w; + int y = index / w; + QRect r(x * m_size, y * m_size, m_size, m_size); + painter.eraseRect(r); + update(r); +} + void TilePainter::setTile(int index, const color_t* data) { QPainter painter(&m_backing); int w = width() / m_size; diff --git a/src/platform/qt/TilePainter.h b/src/platform/qt/TilePainter.h index f4a6bdc96..5ef4b0555 100644 --- a/src/platform/qt/TilePainter.h +++ b/src/platform/qt/TilePainter.h @@ -22,6 +22,7 @@ public: QPixmap backing() const { return m_backing; } public slots: + void clearTile(int index); void setTile(int index, const color_t*); void setTileCount(int tiles); void setTileMagnification(int mag);