Qt: Fix crash in sprite view for partially out-of-bounds sprites (fixes #2165)

This commit is contained in:
Vicki Pfau 2021-05-09 01:46:11 -07:00
parent cce8ab2cd1
commit d990f9bdb7
4 changed files with 22 additions and 6 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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);