[Bf-blender-cvs] [d9b7655] gooseberry: Fix for invalid access to undefined hair data in edge-only cloth meshes.

Lukas Tönne noreply at git.blender.org
Mon Dec 22 11:57:17 CET 2014


Commit: d9b7655bbdf31400d9e8bd2ee904fc7b60dea52f
Author: Lukas Tönne
Date:   Mon Dec 22 11:54:24 2014 +0100
Branches: gooseberry
https://developer.blender.org/rBd9b7655bbdf31400d9e8bd2ee904fc7b60dea52f

Fix for invalid access to undefined hair data in edge-only cloth meshes.

Cloth data is used both for hair and actual cloth, which makes things
really difficult. The face number was used for distinguishing the two
types (no faces == hair mesh), but the extra hair data necessary for
hair sim is generated by particles and not available for edge-only cloth
meshes. This really needs to be sanitized ...

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

M	source/blender/blenkernel/intern/cloth.c
M	source/blender/physics/intern/BPH_mass_spring.cpp

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

diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 78abf7b..72a3587 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -1064,13 +1064,16 @@ static void cloth_free_errorsprings(Cloth *cloth,  LinkNode **edgelist)
 	}
 }
 
-static void cloth_update_bending_targets(ClothModifierData *clmd)
+static void cloth_hair_update_bending_targets(ClothModifierData *clmd)
 {
 	Cloth *cloth = clmd->clothObject;
 	LinkNode *search = NULL;
 	float hair_frame[3][3], dir_old[3], dir_new[3];
 	int prev_mn; /* to find hair chains */
 	
+	if (!clmd->hairdata)
+		return;
+	
 	/* XXX Note: we need to propagate frames from the root up,
 	 * but structural hair springs are stored in reverse order.
 	 * The bending springs however are then inserted in the same
@@ -1136,13 +1139,16 @@ static void cloth_update_bending_targets(ClothModifierData *clmd)
 	}
 }
 
-static void cloth_update_bending_rest_targets(ClothModifierData *clmd)
+static void cloth_hair_update_bending_rest_targets(ClothModifierData *clmd)
 {
 	Cloth *cloth = clmd->clothObject;
 	LinkNode *search = NULL;
 	float hair_frame[3][3], dir_old[3], dir_new[3];
 	int prev_mn; /* to find hair roots */
 	
+	if (!clmd->hairdata)
+		return;
+	
 	/* XXX Note: we need to propagate frames from the root up,
 	 * but structural hair springs are stored in reverse order.
 	 * The bending springs however are then inserted in the same
@@ -1235,7 +1241,7 @@ static void cloth_update_springs( ClothModifierData *clmd )
 		search = search->next;
 	}
 	
-	cloth_update_bending_targets(clmd);
+	cloth_hair_update_bending_targets(clmd);
 }
 
 BLI_INLINE void cross_identity_v3(float r[3][3], const float v[3])
@@ -1514,7 +1520,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm )
 			}
 		}
 		
-		cloth_update_bending_rest_targets(clmd);
+		cloth_hair_update_bending_rest_targets(clmd);
 	}
 	
 	/* note: the edges may already exist so run reinsert */
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 77ce234..9569fd0 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -51,6 +51,8 @@ extern "C" {
 #include "BPH_mass_spring.h"
 #include "implicit.h"
 
+static float I3[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}};
+
 BLI_INLINE bool exclude_vertex(Cloth *cloth, int index)
 {
 	return cloth->verts[index].flags & CLOTH_VERT_FLAG_EXCLUDE;
@@ -181,12 +183,16 @@ void BPH_cloth_solver_set_positions(ClothModifierData *clmd)
 	
 	vert = cloth->verts;
 	for (i = 0; i < numverts; ++i, ++vert) {
-		ClothHairData *root = &cloth_hairdata[i];
-		
 		if (vert->solver_index < 0)
 			continue;
 		
-		BPH_mass_spring_set_rest_transform(id, vert->solver_index, root->rot);
+		if (cloth_hairdata) {
+			ClothHairData *root = &cloth_hairdata[i];
+			BPH_mass_spring_set_rest_transform(id, vert->solver_index, root->rot);
+		}
+		else
+			BPH_mass_spring_set_rest_transform(id, vert->solver_index, I3);
+		
 		BPH_mass_spring_set_motion_state(id, vert->solver_index, vert->x, vert->v);
 	}
 }
@@ -614,9 +620,13 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB
 					if (si_ij < 0 || si_kl < 0)
 						continue;
 					
-					hair_ij = &hairdata[spring->ij];
-					hair_kl = &hairdata[spring->kl];
-					BPH_mass_spring_force_edge_wind(data, si_ij, si_kl, hair_ij->radius, hair_kl->radius, winvec);
+					if (hairdata) {
+						hair_ij = &hairdata[spring->ij];
+						hair_kl = &hairdata[spring->kl];
+						BPH_mass_spring_force_edge_wind(data, si_ij, si_kl, hair_ij->radius, hair_kl->radius, winvec);
+					}
+					else
+						BPH_mass_spring_force_edge_wind(data, si_ij, si_kl, 1.0f, 1.0f, winvec);
 				}
 			}
 #else
@@ -624,9 +634,15 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB
 			
 			vert = cloth->verts;
 			for (i = 0; i < cloth->numverts; i++, vert++) {
-				ClothHairData *hair = &hairdata[i];
+				if (vert->solver_index < 0)
+					continue;
 				
-				BPH_mass_spring_force_vertex_wind(data, i, hair->radius, winvec);
+				if (hairdata) {
+					ClothHairData *hair = &hairdata[i];
+					BPH_mass_spring_force_vertex_wind(data, i, hair->radius, winvec);
+				}
+				else
+					BPH_mass_spring_force_vertex_wind(data, i, 1.0f, winvec);
 			}
 #endif
 		}




More information about the Bf-blender-cvs mailing list