From f5d41263039368b7d0e48f3898ae7ec27f1d4995 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sun, 24 Apr 2022 13:21:37 +0200 Subject: [PATCH] Report when an input "tile" contains too many colors Which otherwise trips a later assertion in debug mode (phew!) and crashes in release mode (oops) --- src/gfx/process.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/gfx/process.cpp b/src/gfx/process.cpp index 2478aaea..d023c511 100644 --- a/src/gfx/process.cpp +++ b/src/gfx/process.cpp @@ -366,13 +366,13 @@ public: class Tile { Png const &_png; - uint32_t const _x, _y; - public: - Tile(Png const &png, uint32_t x, uint32_t y) : _png(png), _x(x), _y(y) {} + uint32_t const x, y; + + Tile(Png const &png, uint32_t x_, uint32_t y_) : _png(png), x(x_), y(y_) {} Rgba pixel(uint32_t xOfs, uint32_t yOfs) const { - return _png.pixel(_x + xOfs, _y + yOfs); + return _png.pixel(x + xOfs, y + yOfs); } }; @@ -922,8 +922,14 @@ void process() { break; // Keep going } } + + // TODO: nicer error message + if (tileColors.size() > options.maxOpaqueColors()) { + fatal("Too many colors in tile at (%" PRIu32 ", %" PRIu32 ")", tile.x, tile.y); + } + attrs.protoPaletteID = protoPalettes.size(); - if (protoPalettes.size() == AttrmapEntry::transparent) { + if (protoPalettes.size() == AttrmapEntry::transparent) { // Check for overflow abort(); // TODO: nice error message } protoPalettes.push_back(tileColors);