Codechange: Don't allocate a text effect with INVALID_TE_ID.

Previously, despite INVALID_TE_ID existing, it was not checked during allocation and there was no limit to the number of text effects.
This commit is contained in:
Peter Nelson 2023-09-09 16:38:12 +01:00 committed by PeterN
parent 78b841d14e
commit 3c61c642a9
1 changed files with 5 additions and 1 deletions

View File

@ -43,7 +43,11 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint8_t duration, Te
if (_game_mode == GM_MENU) return INVALID_TE_ID;
auto it = std::find_if(std::begin(_text_effects), std::end(_text_effects), [](const TextEffect &te) { return te.string_id == INVALID_STRING_ID; });
if (it == std::end(_text_effects)) it = _text_effects.emplace(std::end(_text_effects));
if (it == std::end(_text_effects)) {
/* _text_effects.size() is the maximum ID + 1 that has been allocated. We should not allocate INVALID_TE_ID or beyond. */
if (_text_effects.size() >= INVALID_TE_ID) return INVALID_TE_ID;
it = _text_effects.emplace(std::end(_text_effects));
}
TextEffect &te = *it;