diff --git a/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp b/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp index 6255442c..09166652 100644 --- a/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp +++ b/src/nostalgia/modules/core/include/nostalgia/core/tilesheet.hpp @@ -233,10 +233,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]] @@ -245,8 +247,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); }