diff --git a/CHANGES b/CHANGES index 3855918da..4db830b2e 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/src/platform/qt/AssetTile.cpp b/src/platform/qt/AssetTile.cpp index bda616909..bd9f3a188 100644 --- a/src/platform/qt/AssetTile.cpp +++ b/src/platform/qt/AssetTile.cpp @@ -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; +} diff --git a/src/platform/qt/AssetTile.h b/src/platform/qt/AssetTile.h index d90572018..d6d2510d3 100644 --- a/src/platform/qt/AssetTile.h +++ b/src/platform/qt/AssetTile.h @@ -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; diff --git a/src/platform/qt/MapView.cpp b/src/platform/qt/MapView.cpp index 61347d501..ba2255ee9 100644 --- a/src/platform/qt/MapView.cpp +++ b/src/platform/qt/MapView.cpp @@ -42,6 +42,7 @@ MapView::MapView(std::shared_ptr 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 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")); diff --git a/src/platform/qt/ObjView.cpp b/src/platform/qt/ObjView.cpp index 8764b3f1d..f1b605c0d 100644 --- a/src/platform/qt/ObjView.cpp +++ b/src/platform/qt/ObjView.cpp @@ -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); diff --git a/src/platform/qt/TileView.cpp b/src/platform/qt/TileView.cpp index 3fba7ffd4..116935e29 100644 --- a/src/platform/qt/TileView.cpp +++ b/src/platform/qt/TileView.cpp @@ -51,6 +51,7 @@ TileView::TileView(std::shared_ptr 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 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 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