diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-09-03 05:37:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-09-03 06:28:01 +0300 |
commit | 2820f7be7637e0a4f7edb60f235a876bdc6f0360 (patch) | |
tree | 762400e62a8f37fc516c1d6b7cba6ba0b3761233 /source/blender/blenkernel/intern | |
parent | 7ff7a9c8fdc09f8baeebfcb63de144c7b8d88b3f (diff) |
Fix T80340: Crash with an empty text with Text on Curve
Avoid divide by zero, based on D8780 by @lichtwerk.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/font.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index bb1bf8a98c5..6eaa79d5062 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -1273,7 +1273,13 @@ static bool vfont_to_curve(Object *ob, /* We put the x-coordinate exact at the curve, the y is rotated. */ /* length correction */ - distfac = sizefac * cu->textoncurve->runtime.curve_cache->path->totdist / (maxx - minx); + float chartrans_size_x = maxx - minx; + if (UNLIKELY(chartrans_size_x == 0.0f)) { + /* Happens when there are no characters, + * the result isn't useful in this case, just avoid divide by zero. */ + chartrans_size_x = 1.0f; + } + distfac = sizefac * cu->textoncurve->runtime.curve_cache->path->totdist / chartrans_size_x; timeofs = 0.0f; if (distfac > 1.0f) { @@ -1294,7 +1300,7 @@ static bool vfont_to_curve(Object *ob, distfac = 1.0; } - distfac /= (maxx - minx); + distfac /= chartrans_size_x; timeofs += distfac * cu->xof; /* not cyclic */ |