Qt: Add more bounds checks to tile selection

This commit is contained in:
Vicki Pfau 2022-07-03 18:53:55 -07:00
parent 76d6055bb0
commit 0cfaf0a240
6 changed files with 20 additions and 2 deletions

View File

@ -64,6 +64,7 @@ Other fixes:
- Qt: Fix crash when clicking past last tile in viewer
- Qt: Fix preloading for ROM replacing
- Qt: Fix screen not displaying on Wayland (fixes mgba.io/i/2190)
- Qt: Fix crash when selecting 256-color sprite in sprite view
- VFS: Failed file mapping should return NULL on POSIX
Misc:
- Core: Suspend runloop when a core crashes

View File

@ -82,6 +82,9 @@ void AssetTile::setBoundary(int boundary, int set0, int set1) {
}
void AssetTile::selectIndex(int index) {
if (index > m_maxTile) {
return;
}
m_index = index;
const color_t* data;
mTileCache* tileCache = m_tileCaches[index >= m_boundary];
@ -141,3 +144,7 @@ void AssetTile::selectColor(int index) {
m_ui.g->setText(tr("0x%0 (%1)").arg(g, 2, 16, QChar('0')).arg(g, 2, 10, QChar('0')));
m_ui.b->setText(tr("0x%0 (%1)").arg(b, 2, 16, QChar('0')).arg(b, 2, 10, QChar('0')));
}
void AssetTile::setMaxTile(int tile) {
m_maxTile = tile;
}

View File

@ -29,6 +29,7 @@ public slots:
void selectIndex(int);
void setFlip(bool h, bool v);
void selectColor(int);
void setMaxTile(int);
protected:
int customLocation(const QString& id = {}) override;
@ -45,6 +46,7 @@ private:
int m_addressBase;
int m_boundary;
int m_boundaryBase;
int m_maxTile;
bool m_flipH = false;
bool m_flipV = false;

View File

@ -42,6 +42,7 @@ MapView::MapView(std::shared_ptr<CoreController> controller, QWidget* parent)
#ifdef M_CORE_GBA
case mPLATFORM_GBA:
m_boundary = 2048;
m_ui.tile->setMaxTile(3096);
m_addressBase = BASE_VRAM;
m_addressWidth = 8;
m_ui.bgInfo->addCustomProperty("priority", tr("Priority"));
@ -55,6 +56,7 @@ MapView::MapView(std::shared_ptr<CoreController> controller, QWidget* parent)
#ifdef M_CORE_GB
case mPLATFORM_GB:
m_boundary = 1024;
m_ui.tile->setMaxTile(512);
m_addressBase = GB_BASE_VRAM;
m_addressWidth = 4;
m_ui.bgInfo->addCustomProperty("screenBase", tr("Map base"));

View File

@ -116,14 +116,16 @@ void ObjView::updateTilesGBA(bool force) {
if (GBAObjAttributesAIs256Color(obj->a)) {
m_ui.palette->setText("256-color");
m_ui.tile->setBoundary(1024, 1, 3);
m_ui.tile->setPalette(0);
m_boundary = 1024;
tileBase *= 2;
m_ui.tile->setMaxTile(1536);
m_ui.tile->setPalette(0);
} else {
m_ui.palette->setText(QString::number(newInfo.paletteId));
m_ui.tile->setBoundary(2048, 0, 2);
m_ui.tile->setPalette(newInfo.paletteId);
m_boundary = 2048;
m_ui.tile->setMaxTile(3072);
m_ui.tile->setPalette(newInfo.paletteId);
}
if (newInfo != m_objInfo) {
force = true;
@ -225,6 +227,7 @@ void ObjView::updateTilesGB(bool force) {
m_objInfo = newInfo;
m_tileOffset = tile;
m_boundary = 1024;
m_ui.tile->setMaxTile(512);
int i = 0;
m_ui.tile->setPalette(newInfo.paletteId);

View File

@ -51,6 +51,7 @@ TileView::TileView(std::shared_ptr<CoreController> controller, QWidget* parent)
#ifdef M_CORE_GBA
case mPLATFORM_GBA:
m_ui.tile->setBoundary(2048, 0, 2);
m_ui.tile->setMaxTile(3096);
break;
#endif
#ifdef M_CORE_GB
@ -60,6 +61,7 @@ TileView::TileView(std::shared_ptr<CoreController> controller, QWidget* parent)
m_ui.tilesBoth->setEnabled(false);
m_ui.palette256->setEnabled(false);
m_ui.tile->setBoundary(1024, 0, 0);
m_ui.tile->setMaxTile(512);
break;
#endif
default:
@ -74,6 +76,7 @@ TileView::TileView(std::shared_ptr<CoreController> controller, QWidget* parent)
#ifdef M_CORE_GBA
case mPLATFORM_GBA:
m_ui.tile->setBoundary(2048 >> selected, selected, selected + 2);
m_ui.tile->setMaxTile(3096 >> selected);
break;
#endif
#ifdef M_CORE_GB