[Bf-blender-cvs] [a4c953bf048] fracture_modifier: attempt to reduce memory usage with dynamic fracture

Martin Felke noreply at git.blender.org
Mon Aug 7 17:58:28 CEST 2017


Commit: a4c953bf048ce9d5284bf20e501a9f3816202128
Author: Martin Felke
Date:   Mon Aug 7 17:58:04 2017 +0200
Branches: fracture_modifier
https://developer.blender.org/rBa4c953bf048ce9d5284bf20e501a9f3816202128

attempt to reduce memory usage with dynamic fracture

but somewhere a memory leak is still present there

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

M	intern/rigidbody/rb_bullet_api.cpp
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index 337fc97ba8b..1ef84bd92c8 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -319,7 +319,8 @@ static void tickCallback(btDynamicsWorld *world, btScalar timeStep)
 				const btVector3& normalOnB = pt.m_normalWorldOnB;*/
 
 				//TickDiscreteDynamicsWorld* tworld = (TickDiscreteDynamicsWorld*)world;
-				if (tworld->m_contactCallback)
+				//odd check, but in debug mode we had already numcontacts = 2 but didnt have ANY contacts... gah
+				if (tworld->m_contactCallback && j < contactManifold->getNumContacts())
 				{
 
 					rbContactPoint* cp = tworld->make_contact_point(pt, obA, obB);
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index ede2ed21b6e..cc40ce61d7d 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -1354,6 +1354,13 @@ static int  ptcache_rigidbody_write(int index, void *rb_v, void **data, int cfra
 //			if (frame < 0) // GAAAAH!
 //				frame = 0;
 
+			//grow array if necessary...
+			if (frame >= mi->frame_count) {
+				mi->frame_count = frame+1;
+				mi->locs = MEM_reallocN(mi->locs, sizeof(float) * 3 * mi->frame_count);
+				mi->rots = MEM_reallocN(mi->rots, sizeof(float) * 4 * mi->frame_count);
+			}
+
 			mi->locs[3*frame] = rbo->pos[0];
 			mi->locs[3*frame+1] = rbo->pos[1];
 			mi->locs[3*frame+2] = rbo->pos[2];
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index a8b4ae61c1d..65737110b3a 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -305,75 +305,7 @@ static void free_simulation(FractureModifierData *fmd, bool do_free_seq, bool do
 	BKE_free_constraints(fmd);
 
 	if (!do_free_seq) {
-
-		if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
-		{
-			//delete all except first sequence elem (really ?)
-			MeshIslandSequence *msq = fmd->meshIsland_sequence.first;
-			ShardSequence *ssq = fmd->shard_sequence.first;
-
-			if (msq)
-				msq = msq->next;
-
-			while (msq && msq != fmd->meshIsland_sequence.first)
-			{
-				BLI_remlink(&fmd->meshIsland_sequence, msq);
-				free_meshislands(fmd, &msq->meshIslands, do_free_rigidbody);
-				MEM_freeN(msq);
-				msq = fmd->meshIsland_sequence.first;
-				if (msq)
-					msq = msq->next;
-			}
-
-			msq = fmd->meshIsland_sequence.first;
-			if (msq)
-			{
-				msq->is_new = true;
-				fmd->current_mi_entry = msq;
-				fmd->meshIslands = msq->meshIslands;
-				fmd->visible_mesh_cached = msq->visible_dm;
-
-			}
-			else
-			{
-				fmd->meshIsland_sequence.first = NULL;
-				fmd->meshIsland_sequence.last = NULL;
-
-				fmd->meshIslands.first = NULL;
-				fmd->meshIslands.last = NULL;
-
-				fmd->current_mi_entry = NULL;
-			}
-
-			if (ssq)
-				ssq = ssq->next;
-
-			while (ssq && ssq != fmd->shard_sequence.first)
-			{
-				BLI_remlink(&fmd->shard_sequence, ssq);
-				BKE_fracmesh_free(ssq->frac_mesh, true);
-				MEM_freeN(ssq->frac_mesh);
-				MEM_freeN(ssq);
-
-				ssq = fmd->shard_sequence.first;
-				if (ssq)
-					ssq = ssq->next;
-			}
-
-			if (ssq)
-			{
-				fmd->current_shard_entry = ssq;
-				fmd->frac_mesh = ssq->frac_mesh;
-			}
-			else
-			{
-				fmd->shard_sequence.first = NULL;
-				fmd->shard_sequence.last = NULL;
-				fmd->current_shard_entry = NULL;
-				fmd->frac_mesh = NULL;
-			}
-		}
-		else
+		if (fmd->fracture_mode != MOD_FRACTURE_DYNAMIC)
 		{
 			free_meshislands(fmd, &fmd->meshIslands, do_free_rigidbody);
 			fmd->meshIslands.first = NULL;
@@ -408,14 +340,15 @@ static void free_simulation(FractureModifierData *fmd, bool do_free_seq, bool do
 			{
 				ssq = fmd->shard_sequence.first;
 				BLI_remlink(&fmd->shard_sequence, ssq);
-				BKE_fracmesh_free(ssq->frac_mesh, true);
-				MEM_freeN(ssq->frac_mesh);
+				//BKE_fracmesh_free(ssq->frac_mesh, true);
+				//MEM_freeN(ssq->frac_mesh);
 				MEM_freeN(ssq);
 			}
 
 			fmd->shard_sequence.first = NULL;
 			fmd->shard_sequence.last = NULL;
 			fmd->current_shard_entry = NULL;
+			BKE_fracmesh_free(fmd->frac_mesh, true);
 			fmd->frac_mesh = NULL;
 		}
 	}
@@ -2095,7 +2028,7 @@ static float do_setup_meshisland(FractureModifierData *fmd, Object *ob, int totv
 	{
 		/* in dynamic case preallocate cache here */
 		int start = fmd->modifier.scene->rigidbody_world->pointcache->startframe;
-		int end = fmd->modifier.scene->rigidbody_world->pointcache->endframe;
+		int end = 10; //fmd->modifier.scene->rigidbody_world->pointcache->endframe;
 
 		if (fmd->current_mi_entry) {
 			MeshIslandSequence *prev = fmd->current_mi_entry->prev;
@@ -2105,6 +2038,8 @@ static float do_setup_meshisland(FractureModifierData *fmd, Object *ob, int totv
 			}
 		}
 
+		end = start + 10;
+
 		mi->frame_count = end - start + 1;
 		mi->start_frame = start;
 		mi->locs = MEM_mallocN(sizeof(float)*3* mi->frame_count, "mi->locs");
@@ -3736,12 +3671,12 @@ static void do_island_from_shard(FractureModifierData *fmd, Object *ob, Shard* s
 	{
 		/* in dynamic case preallocate cache here */
 		int start = 1;
-		int end = 250;
+		int end = 10;
 
 		if (fmd->modifier.scene->rigidbody_world)
 		{
 			start = fmd->modifier.scene->rigidbody_world->pointcache->startframe;
-			end = fmd->modifier.scene->rigidbody_world->pointcache->endframe;
+			//end = fmd->modifier.scene->rigidbody_world->pointcache->endframe;
 		}
 
 		if (fmd->current_mi_entry) {
@@ -3752,6 +3687,8 @@ static void do_island_from_shard(FractureModifierData *fmd, Object *ob, Shard* s
 			}
 		}
 
+		end = start + 10;
+
 		mi->frame_count = end - start + 1;
 		mi->start_frame = start;
 		mi->locs = MEM_mallocN(sizeof(float)*3* mi->frame_count, "mi->locs");
@@ -4603,7 +4540,7 @@ static ShardSequence* shard_sequence_add(FractureModifierData* fmd, float frame,
 		ssq->frac_mesh = fmd->frac_mesh;
 	}
 	else {
-		ssq->frac_mesh = copy_fracmesh(fmd->frac_mesh);
+		ssq->frac_mesh = fmd->frac_mesh; //copy_fracmesh(fmd->frac_mesh);
 	}
 
 	ssq->is_new = true;




More information about the Bf-blender-cvs mailing list