[Bf-blender-cvs] [8dfff7d] fracture_modifier: partial crash fix for dynamic fractal fracture, can still crash in carve and bullet (todo)

Martin Felke noreply at git.blender.org
Fri Nov 25 18:19:49 CET 2016


Commit: 8dfff7d339e746f7f2b50659b0db734e0e81f59c
Author: Martin Felke
Date:   Fri Nov 25 18:19:27 2016 +0100
Branches: fracture_modifier
https://developer.blender.org/rB8dfff7d339e746f7f2b50659b0db734e0e81f59c

partial crash fix for dynamic fractal fracture, can still crash in carve and bullet (todo)

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

M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenkernel/intern/fracture_util.c

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

diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index d53250e..5ab536b 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -558,7 +558,7 @@ static void handle_boolean_fractal(Shard* s, Shard* t, int expected_shards, Deri
 
 	/*continue with "halves", randomly*/
 	if ((*i) == 0) {
-		*dm_p = dm_parent;
+		*dm_p = CDDM_copy(dm_parent);
 	}
 
 	while (s == NULL || s2 == NULL) {
@@ -623,7 +623,7 @@ static void handle_boolean_fractal(Shard* s, Shard* t, int expected_shards, Deri
 
 			Shard *p = (*tempresults)[j];
 
-			if (*dm_p != dm_parent && *dm_p != NULL) {
+			if (*dm_p != NULL) {
 				(*dm_p)->needsFree = 1;
 				(*dm_p)->release(*dm_p);
 			}
@@ -700,12 +700,12 @@ static void do_prepare_cells(FracMesh *fm, cell *cells, int expected_shards, int
 
 	if ((algorithm == MOD_FRACTURE_BOOLEAN) || (algorithm == MOD_FRACTURE_BOOLEAN_FRACTAL)) {
 		MPoly *mpoly, *mp;
-		int totpoly, i;
+		int totpoly, po;
 
 		*dm_parent = BKE_shard_create_dm(p, true);
 		mpoly = (*dm_parent)->getPolyArray(*dm_parent);
 		totpoly = (*dm_parent)->getNumPolys(*dm_parent);
-		for (i = 0, mp = mpoly; i < totpoly; i++, mp++) {
+		for (po = 0, mp = mpoly; po < totpoly; po++, mp++) {
 			mp->flag &= ~ME_FACE_SEL;
 		}
 	}
@@ -893,7 +893,7 @@ static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, Fra
 		if (!fm->last_shard_tree /*&& (fm->shard_count > 0)*/ && mode == MOD_FRACTURE_PREFRACTURED)
 		{
 			Shard *t;
-			int i = 0;
+			int ti = 0;
 			count = BLI_listbase_count(&fm->shard_map);
 			fm->shard_count = count;
 			if (do_tree)
@@ -913,7 +913,7 @@ static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, Fra
 					BLI_kdtree_insert(fm->last_shard_tree, i, t->raw_centroid);
 				}
 				fm->last_shards[i] = t;
-				i++;
+				ti++;
 			}
 
 			if (do_tree)
@@ -1025,8 +1025,7 @@ static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, Fra
 		dm_p = NULL;
 	}
 
-	//if (p->shard_id == -2)
-	if (p && (parent_id == -2 /*|| parent_id == -1*/))
+	if (p && (parent_id == -2))// || p->shard_id == -2))
 	{
 		BLI_remlink_safe(&fm->shard_map, p);
 		BKE_shard_free(p, true);
@@ -1063,11 +1062,11 @@ static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, Fra
 			//printf("ADDED: %d %d %d\n", i, j, s->shard_id);
 			if (parent_id > -1)
 			{
-				int i = 0;
+				int si = 0;
 				MVert *v;
 
 				sub_v3_v3(s->centroid, pcentroid);
-				for (i = 0, v = s->mvert; i < s->totvert; i++, v++)
+				for (si = 0, v = s->mvert; si < s->totvert; si++, v++)
 				{
 					sub_v3_v3(v->co, pcentroid);
 				}
@@ -2025,7 +2024,7 @@ DerivedMesh *BKE_shard_create_dm(Shard *s, bool doCustomData)
 	CDDM_calc_normals_mapping(dm);
 
 	if (doCustomData) {
-		if (s->totvert > 1) {
+		if (s->totvert > 0) {
 			BKE_copy_customdata_layers(&dm->vertData, &s->vertData, CD_MDEFORMVERT, s->totvert);
 		}
 		if (s->totloop > 0) {
diff --git a/source/blender/blenkernel/intern/fracture_util.c b/source/blender/blenkernel/intern/fracture_util.c
index 151cf5a..3833a79 100644
--- a/source/blender/blenkernel/intern/fracture_util.c
+++ b/source/blender/blenkernel/intern/fracture_util.c
@@ -402,13 +402,14 @@ static Shard *do_output_shard_dm(DerivedMesh** output_dm, Shard *child, int num_
 	return output_s;
 }
 
-static BMesh* do_fractal(float radius, float mat[4][4], bool use_smooth_inner, short inner_material_index,
-                         int num_levels, int num_cuts, float fractal, DerivedMesh** left_dm)
+static DerivedMesh* do_fractal(float radius, float mat[4][4], bool use_smooth_inner, short inner_material_index,
+                         int num_levels, int num_cuts, float fractal)
 {
 	BMFace* f;
 	BMIter iter;
 	BMesh *bm;
 	int i;
+	DerivedMesh *ret = NULL;
 
 	/*create a grid plane */
 	bm = BM_mesh_create(&bm_mesh_allocsize_default,  &((struct BMeshCreateParams){.use_toolflags = true,}));
@@ -454,9 +455,10 @@ static BMesh* do_fractal(float radius, float mat[4][4], bool use_smooth_inner, s
 	}
 
 	/*convert back*/
-	*left_dm = CDDM_from_bmesh(bm, true);
+	ret = CDDM_from_bmesh(bm, false);
+	BM_mesh_free(bm);
 
-	return bm;
+	return ret;
 }
 
 static bool do_check_watertight_other(DerivedMesh **other_dm, DerivedMesh **output_dm, Shard **other, DerivedMesh *right_dm,
@@ -494,7 +496,7 @@ static bool do_check_watertight_other(DerivedMesh **other_dm, DerivedMesh **outp
 	return do_return;
 }
 
-static bool do_check_watertight(DerivedMesh **output_dm, BMesh** bm, DerivedMesh** left_dm, DerivedMesh *right_dm, Shard **other, float mat[4][4])
+static bool do_check_watertight(DerivedMesh **output_dm, DerivedMesh** left_dm, DerivedMesh *right_dm, Shard **other, float mat[4][4])
 {
 	bool do_return = false;
 
@@ -503,10 +505,6 @@ static bool do_check_watertight(DerivedMesh **output_dm, BMesh** bm, DerivedMesh
 		{
 			if (other != NULL)
 				*other = NULL;
-			if (*bm != NULL) {
-				BM_mesh_free(*bm);
-				*bm = NULL;
-			}
 
 			if (*left_dm != NULL) {
 				(*left_dm)->needsFree = 1;
@@ -556,11 +554,9 @@ Shard *BKE_fracture_shard_boolean(Object *obj, DerivedMesh *dm_parent, Shard *ch
                                   bool use_smooth_inner, int num_levels, char uv_layer[64], int solver, float thresh)
 {
 	DerivedMesh *left_dm = NULL, *right_dm, *output_dm, *other_dm;
-	BMesh* bm = NULL;
-
 	if (other != NULL && mat != NULL)
 	{
-		bm = do_fractal(radius, mat, use_smooth_inner, inner_material_index, num_levels, num_cuts, fractal, &left_dm);
+		left_dm = do_fractal(radius, mat, use_smooth_inner, inner_material_index, num_levels, num_cuts, fractal);
 	}
 	else
 	{
@@ -583,16 +579,13 @@ Shard *BKE_fracture_shard_boolean(Object *obj, DerivedMesh *dm_parent, Shard *ch
 	}
 
 	/*check for watertightness, but for fractal only*/
-	if (other != NULL && do_check_watertight(&output_dm, &bm, &left_dm, right_dm, other, mat))
+	if (other != NULL && do_check_watertight(&output_dm, &left_dm, right_dm, other, mat))
 	{
 		return NULL;
 	}
 
 	if (other != NULL)
 	{
-		if (bm != NULL)
-			BM_mesh_free(bm);
-
 		if (solver == eBooleanModifierSolver_Carve)
 		{
 			other_dm = NewBooleanDerivedMesh(left_dm, obj, right_dm, obj, 3);




More information about the Bf-blender-cvs mailing list