From 23c46e1abfe53de5336968565c55de5428efcff1 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 28 Apr 2023 21:07:56 +0100 Subject: [PATCH] Fix: #10735: {POP_COLOUR} fails if string is drawn with extra flags. --- src/gfx_layout.h | 3 ++- src/gfx_type.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gfx_layout.h b/src/gfx_layout.h index 15248a277d..c9790556ea 100644 --- a/src/gfx_layout.h +++ b/src/gfx_layout.h @@ -47,7 +47,8 @@ struct FontState { */ inline void SetColour(TextColour c) { - assert(c >= TC_BLUE && c <= TC_BLACK); + assert((c & TC_COLOUR_MASK) >= TC_BLUE && (c & TC_COLOUR_MASK) <= TC_BLACK); + assert((c & (TC_COLOUR_MASK | TC_FLAGS_MASK)) == c); if ((this->cur_colour & TC_FORCED) == 0) this->cur_colour = c; } diff --git a/src/gfx_type.h b/src/gfx_type.h index 12d2b2c794..50ac4f6892 100644 --- a/src/gfx_type.h +++ b/src/gfx_type.h @@ -279,6 +279,9 @@ enum TextColour { TC_IS_PALETTE_COLOUR = 0x100, ///< Colour value is already a real palette colour index, not an index of a StringColour. TC_NO_SHADE = 0x200, ///< Do not add shading to this text colour. TC_FORCED = 0x400, ///< Ignore colour changes from strings. + + TC_COLOUR_MASK = 0xFF, ///< Mask to test if TextColour (without flags) is within limits. + TC_FLAGS_MASK = 0x700, ///< Mask to test if TextColour (with flags) is within limits. }; DECLARE_ENUM_AS_BIT_SET(TextColour)