diff --git a/src/nostalgia/core/studio/tilesheeteditormodel.cpp b/src/nostalgia/core/studio/tilesheeteditormodel.cpp index 2951d793..e769d4a2 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);