[Bf-blender-cvs] [289d8b2] fracture_modifier: dynamic fracture: some crash fixes when changing between prefractured and dynamic mode (memory was partially overwritten instead of cleared)

Martin Felke noreply at git.blender.org
Sat Jun 6 15:51:10 CEST 2015


Commit: 289d8b247e594264f1c931444a63a5e32eae737d
Author: Martin Felke
Date:   Fri Jun 5 19:23:47 2015 +0200
Branches: fracture_modifier
https://developer.blender.org/rB289d8b247e594264f1c931444a63a5e32eae737d

dynamic fracture: some crash fixes when changing between prefractured and dynamic mode (memory was partially overwritten instead of cleared)

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

M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index fb2a670..4588116 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1873,11 +1873,14 @@ static bool check_shard_size(FractureModifierData *fmd, int id, float impact_loc
 		}
 	}
 
-	//simple calc, take just the 1st dimension here.... will be refined later, TODO
-	BKE_object_dimensions_get(collider, dim);
+	if (collider)
+	{
+		//simple calc, take just dimensions here.... will be refined later
+		BKE_object_dimensions_get(collider, dim);
 
-	copy_v3_v3(s->impact_loc, impact_loc);
-	copy_v3_v3(s->impact_size, dim);
+		copy_v3_v3(s->impact_loc, impact_loc);
+		copy_v3_v3(s->impact_size, dim);
+	}
 
 	printf("FRACTURE : %d\n", id);
 
@@ -1905,13 +1908,13 @@ static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw)
 		return;
 	}
 
-	if (linear_index2 > -1)
+	if (linear_index2 > -1 && linear_index2 < rbw->numbodies)
 	{
 		ob_index2 = rbw->cache_offset_map[linear_index2];
 		ob2 = rbw->objects[ob_index2];
 	}
 
-	if (linear_index1 > -1)
+	if (linear_index1 > -1 && linear_index1 < rbw->numbodies)
 	{
 		ob_index1 = rbw->cache_offset_map[linear_index1];
 		ob1 = rbw->objects[ob_index1];
@@ -1936,7 +1939,7 @@ static void check_fracture(rbContactPoint* cp, RigidBodyWorld *rbw)
 		}
 	}
 
-	if (linear_index2 > -1)
+	if (linear_index2 > -1 && linear_index2 < rbw->numbodies)
 	{
 		//ob_index2 = rbw->cache_offset_map[linear_index2];
 		//ob2 = rbw->objects[ob_index2];
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index e012224..b404902 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -447,6 +447,23 @@ static void rna_Modifier_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Point
 	WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ptr->id.data);
 }
 
+static void rna_Modifier_update_and_keep(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+	ModifierData* md = ptr->data;
+
+	if (md && md->type == eModifierType_Fracture)
+	{
+		FractureModifierData *fmd = (FractureModifierData*)md;
+		if (fmd->refresh)
+		{
+			return;
+		}
+	}
+
+	DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
+	WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ptr->id.data);
+}
+
 static void rna_Modifier_dependency_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
 	rna_Modifier_update(bmain, scene, ptr);
@@ -4744,13 +4761,13 @@ static void rna_def_modifier_fracture(BlenderRNA *brna)
 	RNA_def_property_range(prop, 0.0f, FLT_MAX);
 	RNA_def_property_ui_text(prop, "Dynamic force threshold", "Only break dynamically when force is above this threshold");
 	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
-	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update_and_keep");
 
 	prop = RNA_def_property(srna, "limit_impact", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "limit_impact", false);
 	RNA_def_property_ui_text(prop, "Limit Impact", "Activates only shards within the impact object size approximately");
 	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
-	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update_and_keep");
 }
 
 static void rna_def_modifier_datatransfer(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 94a6793..810753e 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -310,11 +310,11 @@ static void free_simulation(FractureModifierData *fmd, bool do_free_seq)
 	/* when freeing meshislands, we MUST get rid of constraints before too !!!! */
 	BKE_free_constraints(fmd);
 
-	if (fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED) {
+	if (!do_free_seq || fmd->meshIsland_sequence.first == NULL) {
 		free_meshislands(fmd, &fmd->meshIslands);
 	}
-	else if (do_free_seq)
-	{
+	else
+	{	
 		/* in dynamic mode we have to get rid of the entire Meshisland sequence */
 		MeshIslandSequence *msq;
 		while (fmd->meshIsland_sequence.first) {
@@ -440,7 +440,7 @@ static void freeData_internal(FractureModifierData *fmd, bool do_free_seq)
 	}
 	else if (!fmd->refresh_constraints) {
 		/* refreshing all simulation data only, no refracture */
-		free_simulation(fmd, false); // in this case keep the meshisland sequence!
+		free_simulation(fmd, fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED); // in this case keep the meshisland sequence!
 	}
 	else if (fmd->refresh_constraints) {
 		/* refresh constraints only */
@@ -1284,7 +1284,7 @@ static void do_fracture(FractureModifierData *fmd, ShardID id, Object *obj, Deri
 		{
 			fmd->frac_mesh->running = 0;
 			fmd->refresh = true;
-			freeData_internal(fmd, false);
+			freeData_internal(fmd, fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED);
 			fmd->frac_mesh = NULL;
 			fmd->refresh = false;
 			MEM_freeN(points.points);
@@ -3050,7 +3050,7 @@ static DerivedMesh *output_dm(FractureModifierData* fmd, DerivedMesh *dm, bool e
 		if (fmd->visible_mesh == NULL && fmd->visible_mesh_cached == NULL) {
 			/* oops, something went definitely wrong... */
 			fmd->refresh = true;
-			freeData_internal(fmd, false);
+			freeData_internal(fmd, fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED);
 			fmd->visible_mesh_cached = NULL;
 			fmd->refresh = false;
 		}
@@ -3291,7 +3291,7 @@ static DerivedMesh *doSimulate(FractureModifierData *fmd, Object *ob, DerivedMes
 			(fmd->refresh_constraints && fmd->execute_threaded && fmd->frac_mesh && fmd->frac_mesh->running == 0))
 		{
 			/* if we changed the fracture parameters */
-			freeData_internal(fmd, false);
+			freeData_internal(fmd, fmd->fracture_mode == MOD_FRACTURE_PREFRACTURED);
 
 			/* 2 cases, we can have a visible mesh or a cached visible mesh, the latter primarily when loading blend from file or using halving */
 			/* free cached mesh in case of "normal refracture here if we have a visible mesh, does that mean REfracture ?*/




More information about the Bf-blender-cvs mailing list