diff options
author | Joshua Leung <aligorith@gmail.com> | 2013-06-09 16:05:29 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2013-06-09 16:05:29 +0400 |
commit | 79ef7169e9b9fc94088759cb254ba24b6dab096a (patch) | |
tree | 7c635996f07751d83f302d68ee75e09c1b82fe16 /source | |
parent | d749413ef73db693dd6661e91685f1e390675b29 (diff) |
Bugfix [#35686] Grease pencil to curve conversion causes NAN weights on vertices
When you convert a grease pencil stroke to a polygon curve and look at the
vertices, the first and last vertex have weight = 0, but all others have a -NaN
value. This was caused by division by zero issues when minmax_weights[0] ==
minmax_weights[1].
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_edit.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index 286fffb562a..9ee1f59fe21 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -1264,9 +1264,15 @@ static void gp_stroke_norm_curve_weights(Curve *cu, const float minmax_weights[2 { Nurb *nu; const float delta = minmax_weights[0]; - const float fac = 1.0f / (minmax_weights[1] - delta); + float fac; int i; + /* when delta == minmax_weights[0] == minmax_weights[1], we get div by zero [#35686] */ + if (IS_EQ(delta, minmax_weights[1])) + fac = 1.0f; + else + fac = 1.0f / (minmax_weights[1] - delta); + for (nu = cu->nurb.first; nu; nu = nu->next) { if (nu->bezt) { BezTriple *bezt = nu->bezt; @@ -1361,12 +1367,14 @@ static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bG } /* If link_strokes, be sure first and last points have a zero weight/size! */ - if (link_strokes) + if (link_strokes) { gp_stroke_finalize_curve_endpoints(cu); - + } + /* Update curve's weights, if needed */ - if (norm_weights && ((minmax_weights[0] > 0.0f) || (minmax_weights[1] < 1.0f))) + if (norm_weights && ((minmax_weights[0] > 0.0f) || (minmax_weights[1] < 1.0f))) { gp_stroke_norm_curve_weights(cu, minmax_weights); + } /* Create the path animation, if needed */ gp_stroke_path_animation(C, reports, cu, gtd); |