[Bf-blender-cvs] [95a31c8a3ae] fracture_modifier: fix attempt for split shard to island crashes

Martin Felke noreply at git.blender.org
Wed Jan 24 14:29:00 CET 2018


Commit: 95a31c8a3aeb03314856ccb675889c1750a5e02e
Author: Martin Felke
Date:   Wed Jan 24 14:28:36 2018 +0100
Branches: fracture_modifier
https://developer.blender.org/rB95a31c8a3aeb03314856ccb675889c1750a5e02e

fix attempt for split shard to island crashes

customdata was incorrectly freed and corrupted the memory

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

M	source/blender/blenkernel/intern/fracture.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index df9765c8bbb..f399bbef3cd 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -554,7 +554,8 @@ bool BKE_get_shard_minmax(FracMesh *mesh, ShardID id, float min_r[3], float max_
 	return false;
 }
 
-Shard *BKE_create_fracture_shard(MVert *mvert, MPoly *mpoly, MLoop *mloop, MEdge* medge,  int totvert, int totpoly, int totloop, int totedge, bool copy)
+Shard *BKE_create_fracture_shard(MVert *mvert, MPoly *mpoly, MLoop *mloop, MEdge* medge,  int totvert, int totpoly,
+                                 int totloop, int totedge, bool copy)
 {
 	Shard *shard = MEM_mallocN(sizeof(Shard), __func__);
 	shard->totvert = totvert;
@@ -3744,15 +3745,23 @@ void BKE_update_velocity_layer(FractureModifierData *fmd, MeshIsland *mi)
 	float *velX=NULL, *velY=NULL, *velZ = NULL;
 	RigidBodyOb *rbo = mi->rigidbody;
 	Shard *s, *t = NULL;
-	void *pX, *pY, *pZ;
+	void *pX, *pY, *pZ, *spX = NULL, *spY = NULL, *spZ = NULL;
 	float *sX=NULL, *sY=NULL, *sZ=NULL;
 	int i = 0;
+	ListBase *lb;
 
 	if (!dm)
 		return;
 
 	//XXX TODO deal with split shards to islands etc, here take only "real" shards for now
-	for (s = fmd->frac_mesh->shard_map.first; s; s = s->next)
+	if (fmd->shards_to_islands) {
+		lb = &fmd->islandShards;
+	}
+	else {
+		lb = &fmd->frac_mesh->shard_map;
+	}
+
+	for (s = lb->first; s; s = s->next)
 	{
 		if (s->shard_id == mi->id)
 		{
@@ -3777,15 +3786,19 @@ void BKE_update_velocity_layer(FractureModifierData *fmd, MeshIsland *mi)
 
 	if (t)
 	{
-		sX = check_add_layer(NULL, &t->vertData, CD_PROP_FLT, t->totvert, "velX");
-		sY = check_add_layer(NULL, &t->vertData, CD_PROP_FLT, t->totvert, "velY");
-		sZ = check_add_layer(NULL, &t->vertData, CD_PROP_FLT, t->totvert, "velZ");
+		spX = check_add_layer(NULL, &t->vertData, CD_PROP_FLT, t->totvert, "velX");
+		spY = check_add_layer(NULL, &t->vertData, CD_PROP_FLT, t->totvert, "velY");
+		spZ = check_add_layer(NULL, &t->vertData, CD_PROP_FLT, t->totvert, "velZ");
 	}
 
 	for (i = 0; i < mi->vertex_count; i++)
 	{
-		if (sX && sY && sZ)
+		if (spX && spY && spZ)
 		{
+			sX = (float*)spX;
+			sY = (float*)spY;
+			sZ = (float*)spZ;
+
 			sX[i] = rbo->lin_vel[0] + rbo->ang_vel[0];
 			sY[i] = rbo->lin_vel[1] + rbo->ang_vel[1];
 			sZ[i] = rbo->lin_vel[2] + rbo->ang_vel[2];
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 829a00a5f63..00f6e32c020 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -1985,8 +1985,10 @@ static int do_shard_to_island(FractureModifierData *fmd, BMesh* bm_new, ShardID
 		int id = 0;
 
 		dmtemp = CDDM_from_bmesh(bm_new, true);
-		s = BKE_create_fracture_shard(dmtemp->getVertArray(dmtemp), dmtemp->getPolyArray(dmtemp), dmtemp->getLoopArray(dmtemp), dmtemp->getEdgeArray(dmtemp),
-		                              dmtemp->getNumVerts(dmtemp), dmtemp->getNumPolys(dmtemp), dmtemp->getNumLoops(dmtemp), dmtemp->getNumEdges(dmtemp),
+		s = BKE_create_fracture_shard(dmtemp->getVertArray(dmtemp), dmtemp->getPolyArray(dmtemp),
+		                              dmtemp->getLoopArray(dmtemp), dmtemp->getEdgeArray(dmtemp),
+		                              dmtemp->getNumVerts(dmtemp), dmtemp->getNumPolys(dmtemp),
+		                              dmtemp->getNumLoops(dmtemp), dmtemp->getNumEdges(dmtemp),
 		                              true);
 		s = BKE_custom_data_to_shard(s, dmtemp);



More information about the Bf-blender-cvs mailing list