[Bf-blender-cvs] [96339c4cef1] master: Fix T73304: Crash using force fields and hair dynamics

Luca Rood noreply at git.blender.org
Sun Jan 26 15:28:20 CET 2020


Commit: 96339c4cef104a007bafcc38a788a04e6b263ec8
Author: Luca Rood
Date:   Sun Jan 26 15:15:02 2020 +0100
Branches: master
https://developer.blender.org/rB96339c4cef104a007bafcc38a788a04e6b263ec8

Fix T73304: Crash using force fields and hair dynamics

This implements a better heuristic for identifying if cloth or hair is
being dealt with (checking hairdata, instead of primitive_num).

The issue was caused by a change in primitive counting in rBd42a7bbd6ea5

I'm also adding some safeguards to avoid ever computing pressure for
hair. This shouldn't really be necessary, but it's good to be sure.

===================================================================

M	source/blender/physics/intern/BPH_mass_spring.cpp

===================================================================

diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 94eaffd1f91..fcfd713e6be 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -82,6 +82,11 @@ static float cloth_calc_volume(ClothModifierData *clmd)
   Implicit_Data *data = cloth->implicit;
   float vol = 0;
 
+  /* Early exit for hair, as it never has volume. */
+  if (clmd->hairdata) {
+    return 0.0f;
+  }
+
   if (clmd->sim_parms->vgroup_pressure > 0) {
     for (unsigned int i = 0; i < cloth->primitive_num; i++) {
       bool skip_face = false;
@@ -547,8 +552,8 @@ static void cloth_calc_force(
 #ifdef CLOTH_FORCE_DRAG
   BPH_mass_spring_force_drag(data, drag);
 #endif
-  /* handle pressure forces */
-  if (parms->flags & CLOTH_SIMSETTINGS_FLAG_PRESSURE) {
+  /* handle pressure forces (making sure that this never gets computed for hair). */
+  if ((parms->flags & CLOTH_SIMSETTINGS_FLAG_PRESSURE) && (clmd->hairdata == NULL)) {
     /* The difference in pressure between the inside and outside of the mesh.*/
     float pressure_difference = 0.0f;
 
@@ -634,13 +639,14 @@ static void cloth_calc_force(
           effectors, NULL, clmd->sim_parms->effector_weights, &epoint, winvec[i], NULL);
     }
 
-    for (i = 0; i < cloth->primitive_num; i++) {
-      const MVertTri *vt = &tri[i];
-      BPH_mass_spring_force_face_wind(data, vt->tri[0], vt->tri[1], vt->tri[2], winvec);
+    /* Hair has only edges. */
+    if ((clmd->hairdata == NULL) && (cloth->primitive_num > 0)) {
+      for (i = 0; i < cloth->primitive_num; i++) {
+        const MVertTri *vt = &tri[i];
+        BPH_mass_spring_force_face_wind(data, vt->tri[0], vt->tri[1], vt->tri[2], winvec);
+      }
     }
-
-    /* Hair has only edges */
-    if (cloth->primitive_num == 0) {
+    else {
 #if 0
       ClothHairData *hairdata = clmd->hairdata;
       ClothHairData *hair_ij, *hair_kl;



More information about the Bf-blender-cvs mailing list