From 55a16602423cc7261bee90a7d4290fdbe90e8104 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 12 Jan 2025 16:06:24 -0600 Subject: [PATCH] [nostalgia/core] Fix TileSheet validation/repair to ensure pixels gets cleared if there are subsheets --- .../core/include/nostalgia/core/tilesheet.hpp | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp b/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp index 532de0d5..f31a7d18 100644 --- a/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp +++ b/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp @@ -237,10 +237,12 @@ struct TileSheetV4 { [[nodiscard]] constexpr bool valid(TileSheetV4::SubSheet const&ss, int bpp) noexcept { auto const bytes = static_cast(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1); - return ox::all_of(ss.subsheets.begin(), ss.subsheets.end(), - [bpp, bytes](TileSheetV4::SubSheet const&s) { - return bytes == s.pixels.size() && valid(s, bpp); - }); + return + (ss.pixels.empty() || ss.subsheets.empty()) && + ox::all_of(ss.subsheets.begin(), ss.subsheets.end(), + [bpp, bytes](TileSheetV4::SubSheet const&s) { + return bytes == s.pixels.size() && valid(s, bpp); + }); } [[nodiscard]] @@ -249,8 +251,14 @@ constexpr bool valid(TileSheetV4 const&ts) noexcept { } constexpr void repair(TileSheetV4::SubSheet &ss, int bpp) noexcept { - auto const bytes = static_cast(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1); - ss.pixels.resize(bytes); + if (ss.subsheets.empty()) { + auto const bytes = static_cast(ss.columns * ss.rows * PixelsPerTile) / (bpp == 4 ? 2 : 1); + ss.pixels.resize(bytes); + } else { + ss.pixels.clear(); + ss.columns = -1; + ss.rows = -1; + } for (auto &s : ss.subsheets) { repair(s, bpp); }