diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-07-28 07:12:12 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-07-28 07:37:55 +0300 |
commit | d60acd0e94e6339b2772662657a98771bc3d1729 (patch) | |
tree | 879f57353bf86ec107971ea220d779f10f8adcef /extern/curve_fit_nd/intern | |
parent | 3a4c307652e7e58aace0384d7306b28b7626a1d9 (diff) |
Fix crash fitting single point curve
Diffstat (limited to 'extern/curve_fit_nd/intern')
-rw-r--r-- | extern/curve_fit_nd/intern/curve_fit_cubic_refit.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/extern/curve_fit_nd/intern/curve_fit_cubic_refit.c b/extern/curve_fit_nd/intern/curve_fit_cubic_refit.c index c78b79d76ef..9024296395e 100644 --- a/extern/curve_fit_nd/intern/curve_fit_cubic_refit.c +++ b/extern/curve_fit_nd/intern/curve_fit_cubic_refit.c @@ -1156,8 +1156,22 @@ int curve_fit_cubic_to_points_refit_db( k->handles[1] = len_next / 3; } #else - if (is_cyclic) { - len_prev = normalize_vn_vnvn(tan_prev, &points[(knots_len - 2) * dims], &points[(knots_len - 1) * dims], dims); + if (knots_len < 2) { + /* NOP, set dummy values */ + for (uint i = 0; i < knots_len; i++) { + struct Knot *k = &knots[i]; + zero_vn(k->tan[0], dims); + zero_vn(k->tan[1], dims); + k->handles[0] = 0.0; + k->handles[1] = 0.0; +#ifdef USE_LENGTH_CACHE + points_length_cache[i] = 0.0; +#endif + } + } + else if (is_cyclic) { + len_prev = normalize_vn_vnvn( + tan_prev, &points[(knots_len - 2) * dims], &points[(knots_len - 1) * dims], dims); for (uint i_curr = knots_len - 1, i_next = 0; i_next < knots_len; i_curr = i_next++) { struct Knot *k = &knots[i_curr]; #ifdef USE_LENGTH_CACHE @@ -1177,10 +1191,11 @@ int curve_fit_cubic_to_points_refit_db( } else { #ifdef USE_LENGTH_CACHE - points_length_cache[0] = 0.0; - points_length_cache[1] = + points_length_cache[0] = 0.0; + points_length_cache[1] = #endif - len_prev = normalize_vn_vnvn(tan_prev, &points[0 * dims], &points[1 * dims], dims); + len_prev = normalize_vn_vnvn( + tan_prev, &points[0 * dims], &points[1 * dims], dims); copy_vnvn(knots[0].tan[0], tan_prev, dims); copy_vnvn(knots[0].tan[1], tan_prev, dims); knots[0].handles[0] = len_prev / 3; |