From b02ccf8f4a06d750d1638af30c06a51e0e7c4f06 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Thu, 4 Aug 2022 20:37:36 +0200 Subject: [PATCH] Check before attempting to generate empty image This causes a libpng warning then error, but print a better error message Fixes #1016 --- include/gfx/main.hpp | 2 +- src/gfx/reverse.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/gfx/main.hpp b/include/gfx/main.hpp index ad8bd4e4..73063c1c 100644 --- a/include/gfx/main.hpp +++ b/include/gfx/main.hpp @@ -21,7 +21,7 @@ #include "gfx/rgba.hpp" struct Options { - uint16_t reversedWidth = 0; // -r, in pixels + uint16_t reversedWidth = 0; // -r, in tiles bool reverse() const { return reversedWidth != 0; } bool useColorCurve = false; // -C diff --git a/src/gfx/reverse.cpp b/src/gfx/reverse.cpp index 40e4b5ae..0a52fbb0 100644 --- a/src/gfx/reverse.cpp +++ b/src/gfx/reverse.cpp @@ -122,6 +122,9 @@ void reverse() { options.verbosePrint(Options::VERB_INTERM, "Read %zu tilemap entries.\n", nbTileInstances); } + if (nbTileInstances == 0) { + fatal("Cannot generate empty image"); + } if (nbTileInstances > options.maxNbTiles[0] + options.maxNbTiles[1]) { warning("Read %zu tiles, more than the limit of %zu + %zu", nbTileInstances, options.maxNbTiles[0], options.maxNbTiles[1]);