Skip to content

Commit b59bfd0

Browse files
authored
Fix crash drawing an empty string using a TTF font
1 parent bda676b commit b59bfd0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/video/ttf_font.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ TTFFont::draw_text(Canvas& canvas, const std::string& text,
103103
const Vector& pos, FontAlignment alignment, int layer, const Color& color)
104104

105105
{
106+
const float init_y = pos.y - (static_cast<float>(TTF_FontHeight(m_font)) - get_height()) / 2.0f;
107+
106108
float min_x = pos.x;
107-
float last_y = pos.y - (static_cast<float>(TTF_FontHeight(m_font)) - get_height()) / 2.0f;
109+
float last_y = init_y;
108110
float max_width = 0.f;
109111

110112
LineIterator iter(text);
@@ -138,7 +140,7 @@ TTFFont::draw_text(Canvas& canvas, const std::string& text,
138140
last_y += get_height();
139141
}
140142

141-
return Rectf(min_x, pos.y, min_x + max_width, last_y);
143+
return Rectf(min_x, init_y, min_x + max_width, last_y);
142144
}
143145

144146
std::string

0 commit comments

Comments
 (0)