Fix T59565: NaN/crash with zero radius tip of hair curves.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 21 Dec 2018 17:51:13 +0000 (18:51 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 21 Dec 2018 17:54:45 +0000 (18:54 +0100)
intern/cycles/kernel/geom/geom_curve_intersect.h

index b6b58b52a292950116c5bf3f115dbb9b95ecc21b..5cf8713e3a831b7952ffbc3d43c38607f6657c76 100644 (file)
@@ -874,13 +874,15 @@ ccl_device_inline float3 curve_refine(KernelGlobals *kg,
                        float gd = isect->v;
 
                        /* direction from inside to surface of curve */
-                       sd->Ng = (dif - tg * sd->u * l) / (P_curve[0].w + sd->u * l * gd);
+                       float denom = fmaxf(P_curve[0].w + sd->u * l * gd, 1e-8f);
+                       sd->Ng = (dif - tg * sd->u * l) / denom;
 
                        /* adjustment for changing radius */
                        if(gd != 0.0f) {
                                sd->Ng = sd->Ng - gd * tg;
-                               sd->Ng = normalize(sd->Ng);
                        }
+
+                       sd->Ng = normalize(sd->Ng);
                }
 
                sd->N = sd->Ng;