Commit: 3f0c0ed87dc99a62989df86c57150986251abb5e
Author: Mike Erwin
Date:   Fri Oct 14 19:56:50 2016 -0400
Branches: blender2.8
https://developer.blender.org/rB3f0c0ed87dc99a62989df86c57150986251abb5e

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.

===================================================================

M       source/blender/blenfont/intern/blf_font.c

===================================================================

diff --git a/source/blender/blenfont/intern/blf_font.c 
b/source/blender/blenfont/intern/blf_font.c
index 7d73465..42717e6 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -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);

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to