[Bf-blender-cvs] [9888d30] fracture_modifier: fix: crashes with dynamic fracture, but this is still WIP !

Martin Felke noreply at git.blender.org
Mon Jun 1 21:29:35 CEST 2015


Commit: 9888d30bb68b853f8671b390c3eb04bc4929f6bd
Author: Martin Felke
Date:   Mon Jun 1 20:26:57 2015 +0200
Branches: fracture_modifier
https://developer.blender.org/rB9888d30bb68b853f8671b390c3eb04bc4929f6bd

fix: crashes with dynamic fracture, but this is still WIP !

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

M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenloader/intern/readfile.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 12fb4a9..9c4ed10 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -730,41 +730,49 @@ static void parse_cells(cell *cells, int expected_shards, ShardID parent_id, Fra
 		return;
 	}
 
-	//rebuild tree
-	if (fm->last_shard_tree)
-	{
-		BLI_kdtree_free(fm->last_shard_tree);
-		fm->last_shard_tree = NULL;
-	}
-
-	if (fm->last_shards)
+	if (mode == MOD_FRACTURE_PREFRACTURED)
 	{
-		MEM_freeN(fm->last_shards);
-		fm->last_shards = NULL;
-	}
-
-	if (!fm->last_shard_tree && fm->shard_count > 0 &&
-	    mode == MOD_FRACTURE_PREFRACTURED &&
-	    algorithm != MOD_FRACTURE_BISECT_FAST &&
-	    algorithm != MOD_FRACTURE_BISECT_FAST_FILL)
-	{
-		Shard *t;
-		int i = 0;
-		count = BLI_listbase_count(&fm->shard_map);
-		fm->shard_count = count;
-		fm->last_shard_tree = BLI_kdtree_new(expected_shards + count);
-		fm->last_shards = MEM_callocN(sizeof(Shard*) * expected_shards, "last_shards");
+		//rebuild tree
+		if (fm->last_shard_tree)
+		{
+			BLI_kdtree_free(fm->last_shard_tree);
+			fm->last_shard_tree = NULL;
+		}
 
-		//fill tree from current shardmap
-		for (t = fm->shard_map.first; t; t = t->next)
+		if (fm->last_shards)
 		{
-			t->flag &=~ (SHARD_SKIP | SHARD_DELETE);
-			BLI_kdtree_insert(fm->last_shard_tree, i, t->raw_centroid);
-			fm->last_shards[i] = t;
-			i++;
+			MEM_freeN(fm->last_shards);
+			fm->last_shards = NULL;
 		}
 
-		BLI_kdtree_balance(fm->last_shard_tree);
+		if (!fm->last_shard_tree && fm->shard_count > 0 &&
+			mode == MOD_FRACTURE_PREFRACTURED &&
+			algorithm != MOD_FRACTURE_BISECT_FAST &&
+			algorithm != MOD_FRACTURE_BISECT_FAST_FILL)
+		{
+			Shard *t;
+			int i = 0;
+			count = BLI_listbase_count(&fm->shard_map);
+			fm->shard_count = count;
+			fm->last_shard_tree = BLI_kdtree_new(expected_shards + count);
+			fm->last_shards = MEM_callocN(sizeof(Shard*) * expected_shards, "last_shards");
+
+			//fill tree from current shardmap
+			for (t = fm->shard_map.first; t; t = t->next)
+			{
+				t->flag &=~ (SHARD_SKIP | SHARD_DELETE);
+				BLI_kdtree_insert(fm->last_shard_tree, i, t->raw_centroid);
+				fm->last_shards[i] = t;
+				i++;
+			}
+
+			BLI_kdtree_balance(fm->last_shard_tree);
+		}
+	}
+	else
+	{
+		fm->last_shard_tree = NULL;
+		fm->last_shards = NULL;
 	}
 
 	tempshards = MEM_callocN(sizeof(Shard *) * expected_shards, "tempshards");
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index f574742..43291ea 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4872,7 +4872,9 @@ static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd, Obje
 	fmd->vertex_island_map = NULL;
 
 	/*HARDCODING this for now, until we can version it properly, say with 2.75 ? */
-	//fmd->fracture_mode = MOD_FRACTURE_PREFRACTURED;
+	if (fd->fileversion < 275) {
+		fmd->fracture_mode = MOD_FRACTURE_PREFRACTURED;
+	}
 
 	if (fm == NULL || fmd->dm_group) {
 		fmd->dm = NULL;
@@ -4898,6 +4900,9 @@ static void load_fracture_modifier(FileData* fd, FractureModifierData *fmd, Obje
 		Shard *s;
 		int count = 0;
 
+		fm->last_shard_tree = NULL;
+		fm->last_shards = NULL;
+
 		if (fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED)
 		{
 			link_list(fd, &fmd->frac_mesh->shard_map);
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index a4bad19..49e8ae5 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -118,6 +118,8 @@ static FracMesh* copy_fracmesh(FracMesh* fm)
 	fmesh->cancel = 0;
 	fmesh->running = 0;
 	fmesh->progress_counter = 0;
+	fmesh->last_shard_tree = NULL;
+	fmesh->last_shards = NULL;
 
 	return fmesh;
 }
@@ -431,8 +433,10 @@ static void free_modifier(FractureModifierData *fmd, bool do_free_seq)
 			fmd->visible_mesh_cached = NULL;
 		}
 	}
-
-	//free_shards(fmd);
+	else
+	{
+		free_shards(fmd);
+	}
 
 	if (fmd->vert_index_map != NULL) {
 		BLI_ghash_free(fmd->vert_index_map, NULL, NULL);
@@ -3624,6 +3628,9 @@ static void do_modifier(FractureModifierData *fmd, Object *ob, DerivedMesh *dm)
 			else
 			{	/*MOD_FRACTURE_DYNAMIC*/
 				/* in dynamic case, we add a sequence step here and move the "current" pointers*/
+				if (!fmd->dm) {
+					BKE_fracture_create_dm(fmd, true);
+				}
 				add_new_entries(fmd, dm, ob);
 			}
 		}




More information about the Bf-blender-cvs mailing list