[Bf-blender-cvs] [f1714a3] fracture_modifier: fix: skip invalid shards when doing voronoi+bisect+fill, (less than 3 verts), this caused crashes when trying to load files with fracture results being stored this way

Martin Felke noreply at git.blender.org
Sat Feb 21 14:05:11 CET 2015


Commit: f1714a370eecd71173e3c7f3466577abdcb4e88b
Author: Martin Felke
Date:   Sat Feb 21 14:04:05 2015 +0100
Branches: fracture_modifier
https://developer.blender.org/rBf1714a370eecd71173e3c7f3466577abdcb4e88b

fix: skip invalid shards when doing voronoi+bisect+fill, (less than 3 verts), this caused crashes when trying to load files with fracture results being stored this way

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

M	source/blender/blenkernel/intern/fracture_util.c
M	source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenkernel/intern/fracture_util.c b/source/blender/blenkernel/intern/fracture_util.c
index d67e9aa..8e15f4f 100644
--- a/source/blender/blenkernel/intern/fracture_util.c
+++ b/source/blender/blenkernel/intern/fracture_util.c
@@ -664,21 +664,32 @@ Shard *BKE_fracture_shard_bisect(BMesh *bm_orig, Shard *child, float obmat[4][4]
 		BMO_op_finish(bm_parent, &bmop);
 	}
 
-	dm_out = CDDM_from_bmesh(bm_parent, true);
-	output_s = BKE_create_fracture_shard(dm_out->getVertArray(dm_out),
-	                                     dm_out->getPolyArray(dm_out),
-	                                     dm_out->getLoopArray(dm_out),
-	                                     dm_out->getNumVerts(dm_out),
-	                                     dm_out->getNumPolys(dm_out),
-	                                     dm_out->getNumLoops(dm_out), true);
-
-	output_s = BKE_custom_data_to_shard(output_s, dm_out);
-
-	/*XXX TODO this might be wrong by now ... */
-	output_s->neighbor_count = child->neighbor_count;
-	output_s->neighbor_ids = MEM_mallocN(sizeof(int) * child->neighbor_count, __func__);
-	memcpy(output_s->neighbor_ids, child->neighbor_ids, sizeof(int) * child->neighbor_count);
-	BKE_fracture_shard_center_centroid(output_s, output_s->centroid);
+	if (bm_parent->totvert >= 3)
+	{	/* atleast 3 verts form a face, so strip out invalid stuff */
+		dm_out = CDDM_from_bmesh(bm_parent, true);
+		output_s = BKE_create_fracture_shard(dm_out->getVertArray(dm_out),
+											 dm_out->getPolyArray(dm_out),
+											 dm_out->getLoopArray(dm_out),
+											 dm_out->getNumVerts(dm_out),
+											 dm_out->getNumPolys(dm_out),
+											 dm_out->getNumLoops(dm_out), true);
+
+		output_s = BKE_custom_data_to_shard(output_s, dm_out);
+
+		/*XXX TODO this might be wrong by now ... */
+		output_s->neighbor_count = child->neighbor_count;
+		output_s->neighbor_ids = MEM_mallocN(sizeof(int) * child->neighbor_count, __func__);
+		memcpy(output_s->neighbor_ids, child->neighbor_ids, sizeof(int) * child->neighbor_count);
+		BKE_fracture_shard_center_centroid(output_s, output_s->centroid);
+
+		dm_out->needsFree = 1;
+		dm_out->release(dm_out);
+		dm_out = NULL;
+	}
+	else
+	{
+		output_s = NULL;
+	}
 
 	BM_mesh_free(bm_child);
 	BM_mesh_free(bm_parent);
@@ -687,9 +698,7 @@ Shard *BKE_fracture_shard_bisect(BMesh *bm_orig, Shard *child, float obmat[4][4]
 	dm_child->release(dm_child);
 	dm_child = NULL;
 
-	dm_out->needsFree = 1;
-	dm_out->release(dm_out);
-	dm_out = NULL;
+
 
 	return output_s;
 }
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index a781b44..cf20220 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1650,18 +1650,15 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
 					writestruct(wd, DATA, "FracMesh", 1, fm);
 
 					for (s = fm->shard_map.first; s; s = s->next) {
-						if (s->totvert > 1)
-							write_shard(wd, s);
+						write_shard(wd, s);
 					}
 
 					for (s = fmd->islandShards.first; s; s = s->next) {
-						if (s->totvert > 1)
-							write_shard(wd, s);
+						write_shard(wd, s);
 					}
 
 					for (mi = fmd->meshIslands.first; mi; mi = mi->next) {
-						if (mi->vertex_count > 1)
-							write_meshIsland(wd, mi);
+						write_meshIsland(wd, mi);
 					}
 				}
 			}




More information about the Bf-blender-cvs mailing list