[Bf-blender-cvs] [5c3b85a4c9b] temp-fracture-modifier-2.8: removed all known memleaks happening in FM so far

Martin Felke noreply at git.blender.org
Thu Aug 16 22:14:52 CEST 2018


Commit: 5c3b85a4c9b72a8720f3b45416cecae733f1e030
Author: Martin Felke
Date:   Thu Aug 16 22:14:24 2018 +0200
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rB5c3b85a4c9b72a8720f3b45416cecae733f1e030

removed all known memleaks happening in FM so far

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

M	extern/voro++/src/c_interface.cc
M	extern/voro++/src/c_interface.hh
M	source/blender/blenkernel/BKE_fracture.h
M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenkernel/intern/fracture_prefractured.c
M	source/blender/blenkernel/intern/fracture_rigidbody.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/extern/voro++/src/c_interface.cc b/extern/voro++/src/c_interface.cc
index 7344850dd87..a642a87fef1 100644
--- a/extern/voro++/src/c_interface.cc
+++ b/extern/voro++/src/c_interface.cc
@@ -77,6 +77,7 @@ void container_compute_cells(container* con, particle_order* p_order, cell* cell
 				vc.face_vertices(face_verts);
 				c.poly_indices = new int*[c.totpoly];
 				int skip = 0;
+				int loopverts = 0;
 				for (fo = 0; fo < c.totpoly; fo++) {
 					int num_verts = c.poly_totvert[fo];
 					c.poly_indices[fo] = new int[num_verts];
@@ -84,8 +85,11 @@ void container_compute_cells(container* con, particle_order* p_order, cell* cell
 						c.poly_indices[fo][fv] = face_verts[skip + 1 + fv];
 					}
 					skip += (num_verts+1);
+					loopverts += num_verts;
 				}
 
+				c.totloop = loopverts;
+
 				// neighbors
 				vc.neighbors(neighbors);
 				c.neighbors = new int[c.totpoly];
diff --git a/extern/voro++/src/c_interface.hh b/extern/voro++/src/c_interface.hh
index 46a1fa9f418..20757dd422a 100644
--- a/extern/voro++/src/c_interface.hh
+++ b/extern/voro++/src/c_interface.hh
@@ -42,6 +42,7 @@ typedef struct cell {
 	int index;
 	int totvert;
 	int totpoly;
+	int totloop;
 } cell;
 
 container* container_new(double ax_,double bx_,double ay_,double by_,double az_,double bz_,
diff --git a/source/blender/blenkernel/BKE_fracture.h b/source/blender/blenkernel/BKE_fracture.h
index 4306702cbb4..184e3b5f5f7 100644
--- a/source/blender/blenkernel/BKE_fracture.h
+++ b/source/blender/blenkernel/BKE_fracture.h
@@ -204,7 +204,7 @@ void BKE_fracture_dynamic_free(struct FractureModifierData *fmd, struct Scene *s
 void BKE_fracture_external_constraints_setup(struct FractureModifierData *fmd, struct Scene *scene, struct Object *ob);
 void BKE_fracture_dynamic_new_entries_add(struct FractureModifierData* fmd, struct Scene *scene, bool is_new);
 
-struct Mesh* BKE_fracture_apply(struct FractureModifierData *fmd, struct Object *obj, struct Mesh *me, struct Depsgraph* depsgraph);
+struct Mesh* BKE_fracture_apply(struct FractureModifierData *fmd, struct Object *ob, struct Mesh *me, struct Depsgraph* depsgraph);
 
 struct MeshIsland *BKE_fracture_mesh_island_create(struct Mesh* me, struct Main* bmain, struct Scene *scene, struct Object *ob);
 void BKE_fracture_mesh_boundbox_calc(struct Mesh *me, float r_loc[], float r_size[]);
diff --git a/source/blender/blenkernel/intern/fracture.c b/source/blender/blenkernel/intern/fracture.c
index 9a82e523b37..d135288733d 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -93,8 +93,8 @@
 /* prototypes */
 static MeshIsland *parse_cell(cell c);
 static void parse_cell_verts(cell c, MVert *mvert, int totvert);
-static void parse_cell_polys(cell c, MPoly *mpoly, int totpoly, int *r_totloop);
-static void parse_cell_loops(cell c, MLoop *mloop, int totloop, MPoly *mpoly, int totpoly);
+static void parse_cell_polys(cell c, MPoly *mpoly, int totpoly);
+static void parse_cell_loops(cell c, MLoop *mloop, MPoly *mpoly, int totpoly);
 static void parse_cell_neighbors(cell c, int *neighbors, int totpoly);
 static void arrange_shard(FractureModifierData *fmd, MeshIsland *mi, bool do_verts, float cent[3]);
 static void cleanup_arrange_shard(FractureModifierData *fmd, MeshIsland *s, float cent[]);
@@ -102,20 +102,17 @@ static void do_island_index_map(FractureModifierData *fmd, Object *ob);
 static void do_rigidbody(Main* bmain, Scene* scene, MeshIsland* mi, Object* ob, short rb_type, int i);
 
 
-static void fracture_meshisland_add(FractureModifierData *fmd, MeshIsland *mi,
-                                    Object* ob, Scene *scene, Main *bmain)
+static void fracture_meshisland_add(FractureModifierData *fmd, MeshIsland *mi)
 {
 	MVert *mv;
 	int i;
 
+	mul_m4_v3(fmd->shared->splinter_matrix, mi->centroid);
 	for (i = 0, mv = mi->mesh->mvert; i < mi->mesh->totvert; i++, mv++ )
 	{
 		mul_m4_v3(fmd->shared->splinter_matrix, mv->co);
 	}
 
-	mul_m4_v3(fmd->shared->splinter_matrix, mi->centroid);
-	do_rigidbody(bmain, scene, mi, ob, RBO_TYPE_ACTIVE, 0); //id and island_index set by caller
-
 	BLI_addtail(&fmd->shared->mesh_islands, mi);
 }
 
@@ -526,6 +523,11 @@ static void process_cells(FractureModifierData* fmd, Mesh* mesh, Main* bmain, Ob
 			}
 
 			/* if successful, create processed meshisland in FM */
+			if (temp_meshs[i])
+				BKE_fracture_mesh_free(temp_meshs[i]);
+			if (temp_meshs[i+1])
+				BKE_fracture_mesh_free(temp_meshs[i+1]);
+
 			temp_meshs[i] = meshA;
 			temp_meshs[i+1] = meshB;
 
@@ -544,7 +546,7 @@ static void process_cells(FractureModifierData* fmd, Mesh* mesh, Main* bmain, Ob
 		if (temp_meshs[i])
 		{
 			MeshIsland *result = BKE_fracture_mesh_island_create(temp_meshs[i], bmain, scene, ob);
-			fracture_meshisland_add(fmd, result, ob, scene, bmain);
+			fracture_meshisland_add(fmd, result);
 			result->id = j;
 			result->rigidbody->mesh_island_index = j;
 			j++;
@@ -581,7 +583,7 @@ static void process_cells(FractureModifierData* fmd, Mesh* mesh, Main* bmain, Ob
 static MeshIsland *parse_cell(cell c)
 {
 	MeshIsland *mi = MEM_callocN(sizeof(MeshIsland), "mi_cell");
-	Mesh* me = BKE_mesh_new_nomain(c.totvert, 0, 0, 0, c.totpoly);
+	Mesh* me = BKE_mesh_new_nomain(c.totvert, 0, 0, c.totloop, c.totpoly);
 
 	int totpoly = 0, totloop = 0, totvert = 0;
 	float centr[3];
@@ -595,16 +597,12 @@ static MeshIsland *parse_cell(cell c)
 
 	totpoly = c.totpoly;
 	if (totpoly > 0) {
-		parse_cell_polys(c, me->mpoly, totpoly, &totloop);
+		parse_cell_polys(c, me->mpoly, totpoly);
 	}
-	else
-		totloop = 0;
 
+	totloop = c.totloop;
 	if (totloop > 0) {
-		/* mesh contains a zero length array already (i think) */
-		me->mloop = MEM_recallocN(me->mloop, sizeof(MLoop) * totloop);
-		me->totloop = totloop;
-		parse_cell_loops(c, me->mloop, totloop, me->mpoly, totpoly);
+		parse_cell_loops(c, me->mloop, me->mpoly, totpoly);
 	}
 
 	if (totpoly > 0) {
@@ -614,10 +612,6 @@ static MeshIsland *parse_cell(cell c)
 	}
 
 	copy_v3_v3(centr, c.centroid);
-
-	//XXXXXXXXX LOOK IT UP !!!! TODO
-	//mi = BKE_fracture_shard_create(mvert, mpoly, mloop, NULL, totvert, totpoly, totloop, 0, false);
-
 	copy_v3_v3(mi->centroid, centr);
 	copy_v3_v3(mi->raw_centroid, centr);
 	mi->raw_volume = c.volume;
@@ -638,7 +632,7 @@ static void parse_cell_verts(cell c, MVert *mvert, int totvert)
 	}
 }
 
-static void parse_cell_polys(cell c, MPoly *mpoly, int totpoly, int *r_totloop)
+static void parse_cell_polys(cell c, MPoly *mpoly, int totpoly)
 {
 	int i;
 	int totloop = 0;
@@ -653,11 +647,9 @@ static void parse_cell_polys(cell c, MPoly *mpoly, int totpoly, int *r_totloop)
 
 		totloop += numloop;
 	}
-
-	*r_totloop = totloop;
 }
 
-static void parse_cell_loops(cell c, MLoop *mloop, int UNUSED(totloop), MPoly *mpoly, int totpoly)
+static void parse_cell_loops(cell c, MLoop *mloop, MPoly *mpoly, int totpoly)
 {
 	int i, k;
 
diff --git a/source/blender/blenkernel/intern/fracture_prefractured.c b/source/blender/blenkernel/intern/fracture_prefractured.c
index 26bfae06a0d..223270f8d83 100644
--- a/source/blender/blenkernel/intern/fracture_prefractured.c
+++ b/source/blender/blenkernel/intern/fracture_prefractured.c
@@ -85,18 +85,18 @@ Mesh *BKE_fracture_prefractured_apply(FractureModifierData *fmd, Object *ob, Mes
 MeshIsland *BKE_fracture_mesh_island_create(Mesh* me, Main* bmain, Scene *scene, Object *ob)
 {
 	MeshIsland *mi = MEM_callocN(sizeof(MeshIsland), "mesh_island");
-
 	mi->mesh = me;
-	mi->rigidbody = BKE_rigidbody_create_shard(bmain, scene, ob, NULL, mi);
-	mi->rigidbody->type = RBO_TYPE_ACTIVE;
-	mi->rigidbody->mesh_island_index = 0; // set when adding !!!!
-	BKE_rigidbody_calc_shard_mass(ob, mi);
 
 	INIT_MINMAX(mi->min, mi->max);
 	BKE_mesh_minmax(mi->mesh, mi->min, mi->max);
 	BKE_fracture_mesh_center_centroid_area(mi->mesh, mi->centroid);
 	unit_qt(mi->rot);
 
+	mi->rigidbody = BKE_rigidbody_create_shard(bmain, scene, ob, NULL, mi);
+	mi->rigidbody->type = RBO_TYPE_ACTIVE;
+	mi->rigidbody->mesh_island_index = 0; // set when adding !!!!
+	BKE_rigidbody_calc_shard_mass(ob, mi);
+
 	return mi;
 }
 
@@ -108,6 +108,7 @@ Mesh* BKE_fracture_apply(FractureModifierData *fmd, Object *ob, Mesh *me_orig, D
 	Mesh* me_assembled = NULL;
 	Mesh *me_final = NULL;
 	Mesh *me = me_orig; //BKE_fracture_mesh_copy(me_orig, ob);
+	//Object* ob = DEG_get_evaluated_object(depsgraph, obj);
 
 	if (fmd->shared->refresh)
 	{
@@ -115,7 +116,6 @@ Mesh* BKE_fracture_apply(FractureModifierData *fmd, Object *ob, Mesh *me_orig, D
 		Mesh *me_tmp = NULL;
 
 		// HACK
-		//ob = DEG_get_original_object(obj);
 		fmd->shared->scene = scene;
 
 		/*free old stuff here */
@@ -147,6 +147,7 @@ Mesh* BKE_fracture_apply(FractureModifierData *fmd, Object *ob, Mesh *me_orig, D
 		fmd->shared->refresh_autohide = true;
 
 		//DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE);
+		//DEG_id_tag_update(&ob->id, DEG_TAG_COPY_ON_WRITE);
 	}
 	else if (fmd->shared->refresh_dynamic)
 	{
@@ -175,7 +176,7 @@ Mesh* BKE_fracture_apply(FractureModifierData *fmd, Object *ob, Mesh *me_orig, D
 
 		//if (!fmd->shared->refresh)
 			/* update scene here in case only the constraints updated, dont update twice*/
-		//	DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE);
+		//	DEG_id_tag_update(&ob->id, DEG_TAG_COPY_ON_WRITE);
 	}
 
 	fmd->shared->refresh = false;
diff --git a/source/blender/blenkernel/intern/fracture_rigidbody.c b/source/blender/blenkernel/intern/fracture_rigidbody.c
index bd8df73758e..95f28ab6b13 100644
--- a/source/blender/blenkernel/intern/fracture_rigidbody.c
+++ b/source/blender/blenkernel/intern/fracture_rigidbody.c
@@ -2809,6 +2809,11 @@ RigidBodyOb *BKE_rigidbody_create_shard(Main* bmain, Scene *scene, Object *ob, O
 		return NULL;
 	}
 
+	if (!ob->rigidbody_object) {
+		return NULL;
+	}
+
+#if 0
 	/* Add rigid body world and group if they don't exist for convenience */
 	if (rbw == NULL) {
 		rbw = BKE_rigidbody_create_world(scene);
@@ -2831,6 +2836,7 @@ RigidBodyOb *BKE_rigidbody_create_shard(Main* bmain, Scene *scene, Object *ob, O
 	if (!BKE_collection_has_object(rbw->group, ob)) {
 		BKE_collection_object_add(bmain, rbw->group, ob);
 	}
+#endif
 
 	/* since we are always member of an object, dupe its settings,
 	 * create new 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list