From d87af3d90e381b82bf004ac5082fababcda85bdb Mon Sep 17 00:00:00 2001 From: modawan Date: Mon, 25 Aug 2025 18:25:02 +0900 Subject: [PATCH] Fix font out of bounds exception for non ascii chars Gliphs library has 256 glyphs in total. Lower 128 glyphs are ASCII, higher values are for non-ASCII characters. Char type is 8-bit signed, so we need to bitcast it to unsigned to avoid negative indices. The problem was reported and fixed in https://github.com/seedhartha/reone/pull/61. --- src/libs/graphics/font.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/graphics/font.cpp b/src/libs/graphics/font.cpp index 93741b897..01aa4be6e 100644 --- a/src/libs/graphics/font.cpp +++ b/src/libs/graphics/font.cpp @@ -117,8 +117,8 @@ glm::vec2 Font::getTextOffset(const std::string &text, TextGravity gravity) cons float Font::measure(const std::string &text) const { float w = 0.0f; - for (auto &glyph : text) { - w += _glyphs[static_cast(glyph)].size.x; + for (const char &glyph : text) { + w += _glyphs[reinterpret_cast(glyph)].size.x; } return w; }