BLF: fix crash on text input fields
Some strings have known length, others are NULL terminated (len = INT_MAX in this case). Now font drawing knows to treat INT_MAX special.
This commit is contained in:
parent
9904d73d9a
commit
3f0c0ed87d
|
@ -174,6 +174,21 @@ static void blf_font_ensure_ascii_table(FontBLF *font)
|
|||
} \
|
||||
} (void)0
|
||||
|
||||
static unsigned verts_needed(const FontBLF *font, const char *str, size_t len)
|
||||
{
|
||||
unsigned length = (unsigned)((len == INT_MAX) ? strlen(str) : len);
|
||||
return length * 40;
|
||||
/* (5 shadow + 5 blur) * 4 verts per quad
|
||||
* TODO: determine exact count of quads, somthing like this: */
|
||||
#if 0
|
||||
unsigned quad_ct = 1 + (unsigned)font->blur;
|
||||
if (font->flags & BLF_SHADOW)
|
||||
quad_ct += (unsigned)font->shadow;
|
||||
|
||||
immBegin(GL_QUADS, length * quad_ct * 4);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void blf_font_draw_ex(
|
||||
FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info,
|
||||
int pen_y)
|
||||
|
@ -189,16 +204,7 @@ static void blf_font_draw_ex(
|
|||
|
||||
blf_font_ensure_ascii_table(font);
|
||||
|
||||
immBeginAtMost(GL_QUADS, (unsigned)len * 40);
|
||||
/* (5 shadow + 5 blur) * 4 verts per quad
|
||||
* TODO: determine exact count of quads, somthing like this: */
|
||||
#if 0
|
||||
unsigned quad_ct = 1 + (unsigned)font->blur;
|
||||
if (font->flags & BLF_SHADOW)
|
||||
quad_ct += (unsigned)font->shadow;
|
||||
|
||||
immBegin(GL_QUADS, (unsigned)len * quad_ct * 4);
|
||||
#endif
|
||||
immBeginAtMost(GL_QUADS, verts_needed(font, str, len));
|
||||
|
||||
while ((i < len) && str[i]) {
|
||||
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
|
||||
|
@ -244,7 +250,7 @@ static void blf_font_draw_ascii_ex(
|
|||
|
||||
blf_font_ensure_ascii_table(font);
|
||||
|
||||
immBeginAtMost(GL_QUADS, (unsigned)len * 40);
|
||||
immBeginAtMost(GL_QUADS, verts_needed(font, str, len));
|
||||
|
||||
while ((c = *(str++)) && len--) {
|
||||
BLI_assert(c < 128);
|
||||
|
@ -284,7 +290,7 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
|
|||
|
||||
blf_font_ensure_ascii_table(font);
|
||||
|
||||
immBeginAtMost(GL_QUADS, (unsigned)len * 40);
|
||||
immBeginAtMost(GL_QUADS, verts_needed(font, str, len));
|
||||
|
||||
while ((i < len) && str[i]) {
|
||||
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
|
||||
|
|
Loading…
Reference in New Issue