Page MenuHome

Fix for T91756: String to Curves node produces NaN when size is zero
AbandonedPublic

Authored by Erik Abrahamsson (erik85) on Sep 28 2021, 6:44 PM.

Details

Summary

This patch fixes bug T91756 by setting position to 0 if character offset is indeterminate (font size is 0).

Diff Detail

Repository
rB Blender

Event Timeline

Erik Abrahamsson (erik85) requested review of this revision.Sep 28 2021, 6:44 PM
Erik Abrahamsson (erik85) created this revision.
Hans Goudey (HooglyBoogly) accepted this revision.EditedSep 29 2021, 6:43 AM

I know it's picky, but the float values should be written as 0.0f. Otherwise this looks reasonable. I wonder why the text code is outputting NaNs.. On the other hand I don't blame you for not looking in there. Accepting anyway since this is a trivial change.

This revision is now accepted and ready to land.Sep 29 2021, 6:43 AM

The real fix is even more trivial... Will commit this:

diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 1053b727cbc..0e159418724 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -34,6 +34,7 @@
 #include "BLI_ghash.h"
 #include "BLI_listbase.h"
 #include "BLI_math.h"
+#include "BLI_math_base_safe.h"
 #include "BLI_path_util.h"
 #include "BLI_string.h"
 #include "BLI_string_utf8.h"
@@ -794,8 +795,8 @@ static bool vfont_to_curve(Object *ob,
   bool ok = false;
   const float font_size = cu->fsize * iter_data->scale_to_fit;
   const bool word_wrap = iter_data->word_wrap;
-  const float xof_scale = cu->xof / font_size;
-  const float yof_scale = cu->yof / font_size;
+  const float xof_scale = safe_divide(cu->xof, font_size);
+  const float yof_scale = safe_divide(cu->yof, font_size);
   int last_line = -1;
   /* Length of the text disregarding \n breaks. */
   float current_line_length = 0.0f;
@@ -889,7 +890,7 @@ static bool vfont_to_curve(Object *ob,
   linedist = cu->linedist;
 
   curbox = 0;
-  textbox_scale(&tb_scale, &cu->tb[curbox], 1.0f / font_size);
+  textbox_scale(&tb_scale, &cu->tb[curbox], safe_divide(1.0f, font_size));
   use_textbox = (tb_scale.w != 0.0f);
 
   xof = MARGIN_X_MIN;