SDL: fix a curious crash

This commit is contained in:
Hoe Hao Cheng 2023-07-28 21:33:19 +08:00
parent 1c890be702
commit aaa7e90174

View file

@ -357,6 +357,20 @@ void TextDrawerSDL::DrawStringBitmap(std::vector<uint8_t> &bitmapData, TextStrin
// Replace "&&" with "&"
std::string processedStr = ReplaceAll(str, "&&", "&");
// If a string includes only newlines, SDL2_ttf will refuse to render it
// thinking it is empty. Add a space to avoid that.
bool isAllNewline = true;
for (int i = 0; i < processedStr.size(); i++) {
if (processedStr[i] != '\n') {
isAllNewline = false;
break;
}
}
if (isAllNewline) {
processedStr.push_back(' ');
}
TTF_Font *font = fontMap_.find(fontHash_)->second;
int ptSize = TTF_FontHeight(font) / 1.35;