From 2881a28dc8c1d4febc09c547da3c02a6ea74e8aa Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 17 Mar 2022 04:15:54 -0500 Subject: [PATCH] [nostalgia/core/studio] Fix click bounds checking for TileSheet editor --- src/nostalgia/core/studio/tilesheeteditormodel.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nostalgia/core/studio/tilesheeteditormodel.cpp b/src/nostalgia/core/studio/tilesheeteditormodel.cpp index 2951d7931..e769d4a22 100644 --- a/src/nostalgia/core/studio/tilesheeteditormodel.cpp +++ b/src/nostalgia/core/studio/tilesheeteditormodel.cpp @@ -380,10 +380,10 @@ void TileSheetEditorModel::paste() { void TileSheetEditorModel::drawCommand(const geo::Point &pt, std::size_t palIdx) noexcept { const auto &activeSubSheet = m_img.getSubSheet(m_activeSubsSheetIdx); - const auto idx = activeSubSheet.idx(pt); - if (idx >= activeSubSheet.pixelCnt(m_img.bpp)) { + if (pt.x >= activeSubSheet.columns * TileWidth || pt.y >= activeSubSheet.rows * TileHeight) { return; } + const auto idx = activeSubSheet.idx(pt); if (m_ongoingDrawCommand) { m_updated = m_updated || m_ongoingDrawCommand->append(idx); } else if (activeSubSheet.getPixel(m_img.bpp, idx) != palIdx) { @@ -414,11 +414,11 @@ void TileSheetEditorModel::setActiveSubsheet(const TileSheet::SubSheetIdx &idx) } void TileSheetEditorModel::fill(const geo::Point &pt, int palIdx) noexcept { - const auto s = m_img.getSubSheet(m_activeSubsSheetIdx); + const auto &s = m_img.getSubSheet(m_activeSubsSheetIdx); // build idx list ox::Array updateMap = {}; const auto oldColor = s.getPixel(m_img.bpp, pt); - if (oldColor == palIdx) { + if (pt.x >= s.columns * TileWidth || pt.y >= s.rows * TileHeight) { return; } getFillPixels(updateMap.data(), pt, oldColor);