[Bf-blender-cvs] [e62c4c8] fracture_modifier: fix attempt for crash on loading last blend (quit.blend with dynamic fracture)

Martin Felke noreply at git.blender.org
Thu Mar 31 21:36:12 CEST 2016


Commit: e62c4c822b5f694e41e40e30d928a344bb4bfb43
Author: Martin Felke
Date:   Thu Mar 31 21:36:01 2016 +0200
Branches: fracture_modifier
https://developer.blender.org/rBe62c4c822b5f694e41e40e30d928a344bb4bfb43

fix attempt for crash on loading last blend (quit.blend with dynamic fracture)

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

M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
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 b5550b7..c9a02c8 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -2023,7 +2023,7 @@ void BKE_free_constraints(FractureModifierData *fmd)
 	RigidBodyShardCon *rbsc = NULL;
 
 	for (mi = fmd->meshIslands.first; mi; mi = mi->next) {
-		if (mi->participating_constraints != NULL) {
+		if (mi->participating_constraints != NULL && mi->participating_constraint_count > 0) {
 			MEM_freeN(mi->participating_constraints);
 			mi->participating_constraints = NULL;
 			mi->participating_constraint_count = 0;
@@ -2033,7 +2033,7 @@ void BKE_free_constraints(FractureModifierData *fmd)
 	while (fmd->meshConstraints.first) {
 		rbsc = fmd->meshConstraints.first;
 		BLI_remlink(&fmd->meshConstraints, rbsc);
-		if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
+		if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC && fmd->modifier.scene)
 		{
 			BKE_rigidbody_remove_shard_con(fmd->modifier.scene, rbsc);
 		}
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index dad0d08..c177d50 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -2663,7 +2663,7 @@ RigidBodyWorld *BKE_rigidbody_get_world(Scene *scene)
 void BKE_rigidbody_remove_shard_con(Scene *scene, RigidBodyShardCon *con)
 {
 	RigidBodyWorld *rbw = scene->rigidbody_world;
-	if (rbw && rbw->physics_world && con->physics_constraint) {
+	if (rbw && rbw->physics_world && con && con->physics_constraint) {
 		RB_dworld_remove_constraint(rbw->physics_world, con->physics_constraint);
 		RB_constraint_delete(con->physics_constraint);
 		con->physics_constraint = NULL;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index b89c85e..ac55b2a 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5082,10 +5082,10 @@ static void read_meshIsland(FileData *fd, MeshIsland **address)
 	mi->locs = newdataadr(fd, mi->locs);
 	mi->rots = newdataadr(fd, mi->rots);
 
-	/* will be refreshed on the fly */
-	mi->participating_constraint_count = 0;
-	mi->participating_constraints = NULL;
-	//mi->particle_index = -1;
+	/* will be refreshed on the fly if not there*/
+	mi->participating_constraints = newdataadr(fd, mi->participating_constraints);
+	if (mi->participating_constraints == NULL)
+		mi->participating_constraint_count = 0;
 }
 
 static int initialize_meshisland(FractureModifierData* fmd, MeshIsland** mii, MVert* mverts, int vertstart,
@@ -5157,6 +5157,7 @@ static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd)
 	fmd->defgrp_index_map = NULL;
 	fmd->fracture_ids.first = NULL;
 	fmd->fracture_ids.last = NULL;
+	fmd->update_dynamic = false;
 
 	/*HARDCODING this for now, until we can version it properly, say with 2.75 ? */
 	if (fd->fileversion < 275) {
@@ -5211,6 +5212,7 @@ static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd)
 			MVert *mverts;
 			int vertstart = 0;
 			Shard *s, **shards = NULL;
+			RigidBodyShardCon *con;
 
 			link_list(fd, &fmd->frac_mesh->shard_map);
 			link_list(fd, &fmd->islandShards);
@@ -5288,33 +5290,29 @@ static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd)
 				i++;
 			}
 
-			//if (fmd->fracture_mode == MOD_FRACTURE_EXTERNAL)
+			link_list(fd, &fmd->meshConstraints);
+
+			for (con = fmd->meshConstraints.first; con; con = con->next)
 			{
-				RigidBodyShardCon *con;
-				link_list(fd, &fmd->meshConstraints);
+				con->mi1 = newdataadr(fd, con->mi1);
+				con->mi2 = newdataadr(fd, con->mi2);
+				con->physics_constraint = NULL;
+				con->flag |= RBC_FLAG_NEEDS_VALIDATE;
+			}
 
-				for (con = fmd->meshConstraints.first; con; con = con->next)
+			if (fmd->meshConstraints.first == NULL || fmd->meshConstraints.last == NULL)
+			{	//fallback... rebuild constraints from scratch if none are found
+				if (fmd->fracture_mode != MOD_FRACTURE_EXTERNAL)
 				{
-					con->mi1 = newdataadr(fd, con->mi1);
-					con->mi2 = newdataadr(fd, con->mi2);
-					con->physics_constraint = NULL;
-					con->flag |= RBC_FLAG_NEEDS_VALIDATE;
-				}
-
-				if (fmd->meshConstraints.first == NULL)
-				{	//fallback... rebuild constraints from scratch if none are found
-					if (fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED)
-					{
-						fmd->refresh_constraints = true;
-						fmd->meshConstraints.first = NULL;
-						fmd->meshConstraints.last = NULL;
-					}
+					fmd->refresh_constraints = true;
+					fmd->meshConstraints.first = NULL;
+					fmd->meshConstraints.last = NULL;
 				}
 			}
 
 			MEM_freeN(shards);
 		}
-		else if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC /*&& !fd->memfile*/)
+		else if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
 		{
 			ShardSequence *ssq = NULL;
 			MeshIslandSequence *msq = NULL;
@@ -5369,11 +5367,11 @@ static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd)
 			ssq = fmd->shard_sequence.first;
 			msq = fmd->meshIsland_sequence.first;
 
-			while (ssq->frame < fmd->last_frame) {
+			while (ssq && (ssq->frame < fmd->last_frame)) {
 				ssq = ssq->next;
 			}
 
-			while (msq->frame < fmd->last_frame) {
+			while (msq && (msq->frame < fmd->last_frame)) {
 				msq = msq->next;
 			}
 
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index e0ffac1..0955a0f 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1576,6 +1576,7 @@ static void write_meshIsland(WriteData* wd, MeshIsland* mi)
 
 	writedata(wd, DATA, sizeof(float) * 3 * mi->frame_count, mi->locs);
 	writedata(wd, DATA, sizeof(float) * 4 * mi->frame_count, mi->rots);
+	writedata(wd, DATA, sizeof(RigidBodyShardCon*) * mi->participating_constraint_count, mi->participating_constraints);
 }
 
 static void write_modifiers(WriteData *wd, ListBase *modbase)
@@ -1741,7 +1742,7 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
 					}
 				}
 			}
-			else if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC /*&& !wd->current*/)
+			else if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC)
 			{
 				ShardSequence *ssq;
 				MeshIslandSequence *msq;
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 6eb5ca6..aaf4edb 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -3996,7 +3996,7 @@ static void do_modifier(FractureModifierData *fmd, Object *ob, DerivedMesh *dm)
 
 				if (count > 0)
 				{
-					BKE_free_constraints(fmd);
+					//BKE_free_constraints(fmd);
 					printf("REFRESH: %s \n", ob->id.name);
 					fmd->modifier.scene->rigidbody_world->flag |= RBW_FLAG_OBJECT_CHANGED;
 					fmd->modifier.scene->rigidbody_world->flag &= ~RBW_FLAG_REFRESH_MODIFIERS;




More information about the Bf-blender-cvs mailing list