From: Joshua Leung Date: Sun, 9 Jun 2013 12:05:29 +0000 (+0000) Subject: Bugfix [#35686] Grease pencil to curve conversion causes NAN weights on vertices X-Git-Tag: v2.68~656 X-Git-Url: https://git.blender.org/gitweb/gitweb.cgi/blender.git/commitdiff_plain/79ef7169e9b9fc94088759cb254ba24b6dab096a?hp=d749413ef73db693dd6661e91685f1e390675b29 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]. --- 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);