[Bf-blender-cvs] [cf9221f4eec] temp-fracture-modifier-2.8: fixed some crashes regarding automatic cache reallocation

Martin Felke noreply at git.blender.org
Tue Aug 21 02:31:23 CEST 2018


Commit: cf9221f4eecc0d2344f4a7421c72e860ec1a16a8
Author: Martin Felke
Date:   Tue Aug 21 02:31:02 2018 +0200
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rBcf9221f4eecc0d2344f4a7421c72e860ec1a16a8

fixed some crashes regarding automatic cache reallocation

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

M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenkernel/intern/fracture_prefractured.c
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/makesdna/DNA_fracture_types.h
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 84d033293f8..231d9809db9 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -591,7 +591,7 @@ static void process_cells(FractureModifierData* fmd, MeshIsland* mi, Main* bmain
 			{	/* skip invalid cells, e.g. those which are eliminated by bisect */
 				MeshIsland *result = BKE_fracture_mesh_island_create(temp_meshs[i], bmain, scene, ob, frame);
 				fracture_meshisland_add(fmd, result);
-				result->id = j;
+				result->id = mi->id + j;
 				j++;
 			}
 			else {
@@ -1935,23 +1935,20 @@ void BKE_fracture_meshisland_check_realloc_cache(FractureModifierData *fmd, Rigi
 	int startframe = rbw->shared->pointcache->startframe;
 
 	//only grow...
-	if (endframe != fmd->shared->last_cache_end)
+	if (endframe > fmd->shared->last_cache_end)
 	{
 		//keep invalid shards untouched
-		if (!BKE_fracture_meshisland_check_frame(fmd, mi, frame) && mi->endframe == fmd->shared->last_cache_end)
+		if (!BKE_fracture_meshisland_check_frame(fmd, mi, frame) /*&& mi->endframe == fmd->shared->last_cache_end*/)
 		{
 			mi->endframe = endframe;
-			frame = mi->endframe - frame + 1;
+			frame = mi->endframe;
 
-			mi->locs = MEM_reallocN(mi->locs, sizeof(float*) * 3 * frame);
-			mi->rots = MEM_reallocN(mi->rots, sizeof(float*) * 4 * frame);
-			mi->vels = MEM_reallocN(mi->vels, sizeof(float*) * 3 * frame);
-			mi->aves = MEM_reallocN(mi->aves, sizeof(float*) * 3 * frame);
+			mi->locs = MEM_reallocN(mi->locs, sizeof(float) * 3 * frame);
+			mi->rots = MEM_reallocN(mi->rots, sizeof(float) * 4 * frame);
+			mi->vels = MEM_reallocN(mi->vels, sizeof(float) * 3 * frame);
+			mi->aves = MEM_reallocN(mi->aves, sizeof(float) * 3 * frame);
 		}
 	}
-
-	fmd->shared->last_cache_end = endframe;
-	fmd->shared->last_cache_start = startframe;
 }
 
 void BKE_fracture_meshislands_free(FractureModifierData* fmd, Scene* scene)
@@ -3032,15 +3029,16 @@ void BKE_fracture_do(FractureModifierData *fmd, MeshIsland *mi, Object *obj, Dep
 
 	/* no pointsource means re-use existing mesh islands*/
 	if (fmd->point_source == 0) {
-		int count = 1, i, j = 0;
+		int count = 1, i, j = 1;
 		int frame = (int)(BKE_scene_frame_get(scene)); //TODO ensure original scene !!!
 		Mesh** temp_meshs = MEM_callocN(sizeof(Mesh*) * count, "temp_islands no pointsource");
 		BKE_fracture_split_islands(fmd, obj, mi->mesh, &temp_meshs, &count);
 
 		/* The original mesh island must not be in the collection any more, so unlink and free */
-		BLI_remlink(&fmd->shared->mesh_islands, mi);
-		BKE_fracture_mesh_island_free(mi, scene);
-		mi = NULL;
+		//BLI_remlink(&fmd->shared->mesh_islands, mi);
+		//BKE_fracture_mesh_island_free(mi, scene);
+		//mi = NULL;
+		mi->endframe = frame;
 
 		for (i = 0; i < count; i++)
 		{
@@ -3050,7 +3048,7 @@ void BKE_fracture_do(FractureModifierData *fmd, MeshIsland *mi, Object *obj, Dep
 				{	/* skip invalid cells, e.g. those which are eliminated by bisect */
 					MeshIsland *result = BKE_fracture_mesh_island_create(temp_meshs[i], bmain, scene, obj, frame);
 					fracture_meshisland_add(fmd, result);
-					result->id = j;
+					result->id = mi->id + j;
 					j++;
 				}
 				else {
diff --git a/source/blender/blenkernel/intern/fracture_prefractured.c b/source/blender/blenkernel/intern/fracture_prefractured.c
index e9ffdc08e26..d6411b05c68 100644
--- a/source/blender/blenkernel/intern/fracture_prefractured.c
+++ b/source/blender/blenkernel/intern/fracture_prefractured.c
@@ -84,6 +84,7 @@ Mesh *BKE_fracture_prefractured_apply(FractureModifierData *fmd, Object *ob, Mes
 
 MeshIsland *BKE_fracture_mesh_island_create(Mesh* me, Main* bmain, Scene *scene, Object *ob, int frame)
 {
+	int i;
 	int endframe = scene->rigidbody_world->shared->pointcache->endframe;
 	MeshIsland *mi = MEM_callocN(sizeof(MeshIsland), "mesh_island");
 	mi->mesh = me;
@@ -98,10 +99,10 @@ MeshIsland *BKE_fracture_mesh_island_create(Mesh* me, Main* bmain, Scene *scene,
 
 	if (endframe >= frame) {
 		frame = endframe - frame + 1;
-		mi->locs = MEM_callocN(sizeof (float*) * 3 * frame, "mi->locs");
-		mi->rots = MEM_callocN(sizeof (float*) * 4 * frame, "mi->rots");
-		mi->vels = MEM_callocN(sizeof (float*) * 3 * frame, "mi->vels");
-		mi->aves = MEM_callocN(sizeof (float*) * 3 * frame, "mi->aves");
+		mi->locs = MEM_callocN(sizeof (float) * 3 *frame, "mi->locs");
+		mi->rots = MEM_callocN(sizeof (float) * 4 *frame, "mi->rots");
+		mi->vels = MEM_callocN(sizeof (float) * 3 *frame, "mi->vels");
+		mi->aves = MEM_callocN(sizeof (float) * 3 *frame, "mi->aves");
 	}
 
 	mi->rigidbody = BKE_rigidbody_create_shard(bmain, scene, ob, NULL, mi);
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index f065317d3c4..fe0a4c1e1ff 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -1284,6 +1284,36 @@ static int ptcache_dynamicpaint_read(PTCacheFile *pf, void *dp_v)
 	return 1;
 }
 
+static void copy_to_3(float* dst, float src[3], int index)
+{
+	dst[index * 3] = src[0];
+	dst[index * 3 + 1] = src[1];
+	dst[index * 3 + 2] = src[2];
+}
+
+static void copy_to_4(float* dst, float src[4], int index)
+{
+	dst[index * 4] = src[0];
+	dst[index * 4 + 1] = src[1];
+	dst[index * 4 + 2] = src[2];
+	dst[index * 4 + 3] = src[3];
+}
+
+static void copy_from_3(float dst[3], float* src, int index)
+{
+	dst[0] = src[index * 3];
+	dst[1] = src[index * 3 + 1];
+	dst[2] = src[index * 3 + 2];
+}
+
+static void copy_from_4(float* dst, float src[4], int index)
+{
+	dst[0] = src[index * 4];
+	dst[1] = src[index * 4 + 1];
+	dst[2] = src[index * 4 + 2];
+	dst[3] = src[index * 4 + 3];
+}
+
 /* Rigid Body functions */
 static int  ptcache_rigidbody_write(int index, void *rb_v, void **data, int cfra)
 {
@@ -1311,16 +1341,19 @@ static int  ptcache_rigidbody_write(int index, void *rb_v, void **data, int cfra
 	}
 	else {
 		MeshIsland *mi;
+		bool changed = false;
+
 		for (mi = fmd->shared->mesh_islands.first; mi; mi = mi->next)
 		{
 			int frame = (int)cfra;
-			if (BKE_fracture_meshisland_check_frame(fmd, mi, frame)) {
-				continue;
-			}
 
 			if (frame >= fmd->shared->last_cache_end) {
 				BKE_fracture_meshisland_check_realloc_cache(fmd, rbw, mi, frame);
-				//continue;
+				changed = true;
+			}
+
+			if (BKE_fracture_meshisland_check_frame(fmd, mi, frame)) {
+				continue;
 			}
 
 			rbo = mi->rigidbody;
@@ -1334,15 +1367,21 @@ static int  ptcache_rigidbody_write(int index, void *rb_v, void **data, int cfra
 #endif
 			//ensure valid values here, now !!!
 			frame = frame - mi->startframe;
-			copy_v3_v3(mi->locs[frame], rbo->pos);
-			copy_qt_qt(mi->rots[frame], rbo->orn);
-			copy_v3_v3(mi->vels[frame], rbo->lin_vel);
-			copy_v3_v3(mi->aves[frame], rbo->ang_vel);
+			copy_to_3(mi->locs, rbo->pos, frame);
+			copy_to_4(mi->rots, rbo->orn, frame);
+			copy_to_3(mi->vels, rbo->lin_vel, frame);
+			copy_to_3(mi->aves, rbo->ang_vel, frame);
+		}
+
+		if (changed) {
+			fmd->shared->last_cache_end = rbw->shared->pointcache->endframe;
+			fmd->shared->last_cache_start = rbw->shared->pointcache->startframe;
 		}
 	}
 
 	return 1;
 }
+
 static void ptcache_rigidbody_read(int index, void *rb_v, void **data, float cfra, float *old_data)
 {
 	RigidBodyWorld *rbw = rb_v;
@@ -1384,10 +1423,10 @@ static void ptcache_rigidbody_read(int index, void *rb_v, void **data, float cfr
 
 			//ensure valid values here, now !!!
 			frame = frame - mi->startframe;
-			copy_v3_v3(rbo->pos, mi->locs[frame]);
-			copy_qt_qt(rbo->orn, mi->rots[frame]);
-			copy_v3_v3(rbo->lin_vel, mi->vels[frame]);
-			copy_v3_v3(rbo->ang_vel, mi->aves[frame]);
+			copy_from_3(rbo->pos, mi->locs, frame);
+			copy_from_4(rbo->orn, mi->rots, frame);
+			copy_from_3(rbo->lin_vel, mi->vels, frame);
+			copy_from_3(rbo->ang_vel, mi->aves, frame);
 		}
 	}
 }
@@ -1464,10 +1503,10 @@ static void ptcache_rigidbody_interpolate(int index, void *rb_v, void **data, fl
 				copy_v3_v3(keys[1].vel, rbo->lin_vel);
 				copy_v3_v3(keys[1].ave, rbo->ang_vel);
 
-				copy_v3_v3(keys[2].co, mi->locs[frame2]);
-				copy_qt_qt(keys[2].rot, mi->rots[frame2]);
-				copy_v3_v3(keys[2].vel, mi->vels[frame2]);
-				copy_v3_v3(keys[2].ave, mi->aves[frame2]);
+				copy_from_3(keys[2].co, mi->locs, frame2);
+				copy_from_4(keys[2].rot, mi->rots, frame2);
+				copy_from_3(keys[2].vel, mi->vels, frame2);
+				copy_from_3(keys[2].ave, mi->aves, frame2);
 				keys[2].time = cfra2;
 
 				dfra = cfra2 - cfra1;
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 1fdc194ec4d..f9da4474f35 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -150,7 +150,7 @@ void BKE_rigidbody_free_world(Scene *scene)
 	}
 
 	if (rbw->objects)
-		MEM_freeN(rbw->objects);
+		free(rbw->objects);
 
 	/* free effector weights */
 	if (rbw->effector_weights)
@@ -1059,7 +1059,7 @@ RigidBodyWorld *BKE_rigidbody_create_world(Scene *scene)
 	rbw->flag &=~ RBW_FLAG_OBJECT_CHANGED;
 	rbw->flag &=~ RBW_FLAG_REFRESH_MODIFIERS;
 
-	rbw->objects = MEM_mallocN(sizeof(Object *), "objects");
+	//rbw->objects = MEM_mallocN(sizeof(Object *), "objects");
 
 	/* return this sim world */
 	return rbw;
@@ -1102,45 +1102,16 @@ void BKE_rigidbody_world_groups_relink(RigidBodyWorld *rbw)
 
 void BKE_rigidbody_world_id_loop(RigidBodyWorld *rbw, RigidbodyWorldIDFunc func, void *userdata)
 {
-	CollectionObject *go;
-	int obj, shard;
-
 	func(rbw, (ID **)&rbw->group, userdata, IDWALK_CB_NOP);
 	func(rbw, (ID **)&rbw->constraints, userdata, IDWALK_CB_NOP);
 	func(rbw, (ID **)&rbw->effector_weights->group, userdata, IDWALK_CB_NOP);
 
-	/* in regular blender one rigidbody is equivalent to one object, but in FM build you can have more
-	 * rigidbodies in the world than objects in the object array... thats why loop over the group of objects
-	 * of the rigidbody world... the rbw->objects array would contain group objects only anyway, also dont forget
-	 * regular constraints if there are any */
-
-	/*if (rbw->objects) {
+	if (rbw->objects) {
 		int i;
 		int count = BLI_listbase_count(&rbw->grou

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list