[Bf-blender-cvs] [18675f7] fracture_modifier: another crash fix if simulation was continued after cache end with trigger and constraints, cache might behave incorrectly still if an object is refractured for example, but the others are not

Martin Felke noreply at git.blender.org
Thu Nov 6 15:48:03 CET 2014


Commit: 18675f77fcc97d9ab7c40bd60572cd859e965e74
Author: Martin Felke
Date:   Thu Nov 6 15:47:53 2014 +0100
Branches: fracture_modifier
https://developer.blender.org/rB18675f77fcc97d9ab7c40bd60572cd859e965e74

another crash fix if simulation was continued after cache end with trigger and constraints, cache might behave incorrectly still if an object is refractured for example, but the others are not

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

M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/makesdna/DNA_rigidbody_types.h
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 892caff..1ad29aa 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1455,10 +1455,13 @@ void BKE_rigidbody_validate_sim_shard_constraint(RigidBodyWorld *rbw, RigidBodyS
 	if (rbc->physics_constraint) {
 		if (rebuild == false)
 		{
-			RB_dworld_remove_constraint(rbw->physics_world, rbc->physics_constraint);
+			if (!(rbc->flag & RBC_FLAG_USE_KINEMATIC_DEACTIVATION))
+			{
+				RB_dworld_remove_constraint(rbw->physics_world, rbc->physics_constraint);
+			}
 		}
 	}
-	if (rbc->physics_constraint == NULL || rebuild) {
+	if (rbc->physics_constraint == NULL || rebuild || rbc->flag & RBC_FLAG_USE_KINEMATIC_DEACTIVATION) {
 
 		/* remove constraint if it already exists before creating a new one */
 		if (rbc->physics_constraint) {
@@ -1590,9 +1593,11 @@ void BKE_rigidbody_validate_sim_shard_constraint(RigidBodyWorld *rbw, RigidBodyS
 			RB_constraint_set_solver_iterations(rbc->physics_constraint, -1);
 	}
 
-	if (rbw && rbw->physics_world && rbc->physics_constraint) {
+	if ((rbw && rbw->physics_world && rbc->physics_constraint)) {
 		RB_dworld_add_constraint(rbw->physics_world, rbc->physics_constraint, rbc->flag & RBC_FLAG_DISABLE_COLLISIONS);
 	}
+
+	rbc->flag &= ~RBC_FLAG_USE_KINEMATIC_DEACTIVATION;
 }
 
 //this allows partial object activation, only some shards will be activated, called from bullet(!)
@@ -1643,9 +1648,10 @@ static int filterCallback(void* world, void* island1, void* island2) {
 			for (con = fmd1->meshConstraints.first; con; con = con->next)
 			{
 				RB_dworld_remove_constraint(rbw->physics_world, con->physics_constraint);
-				RB_constraint_delete(con->physics_constraint);
-				con->physics_constraint = NULL;
+				/*RB_constraint_delete(con->physics_constraint);
+				con->physics_constraint = NULL;*/
 				con->flag |= RBC_FLAG_NEEDS_VALIDATE;
+				con->flag |= RBC_FLAG_USE_KINEMATIC_DEACTIVATION;
 			}
 		}
 
@@ -1670,9 +1676,10 @@ static int filterCallback(void* world, void* island1, void* island2) {
 			for (con = fmd2->meshConstraints.first; con; con = con->next)
 			{
 				RB_dworld_remove_constraint(rbw->physics_world, con->physics_constraint);
-				RB_constraint_delete(con->physics_constraint);
-				con->physics_constraint = NULL;
+				/*RB_constraint_delete(con->physics_constraint);
+				con->physics_constraint = NULL;*/
 				con->flag |= RBC_FLAG_NEEDS_VALIDATE;
+				con->flag |= RBC_FLAG_USE_KINEMATIC_DEACTIVATION;
 			}
 		}
 	}
@@ -3020,22 +3027,14 @@ static void restoreKinematic(RigidBodyWorld *rbw)
 			if (fmd)
 			{
 				MeshIsland* mi;
+				RigidBodyShardCon* con;
 				for (mi = fmd->meshIslands.first; mi; mi = mi->next)
 				{
-					RigidBodyShardCon* con;
-					int i = 0;
-
 					if (mi->rigidbody)
 					{
 						mi->rigidbody->flag |= RBO_FLAG_KINEMATIC;
 						mi->rigidbody->flag |= RBO_FLAG_NEEDS_VALIDATE;
 					}
-
-					for (i = 0; i < mi->participating_constraint_count; i++)
-					{
-						con = mi->participating_constraints[i];
-						con->flag |= RBC_FLAG_NEEDS_VALIDATE;
-					}
 				}
 			}
 		}
@@ -3099,7 +3098,6 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
 	if (ctime <= startframe) {
 		/* rebuild constraints */
 		rbw->rebuild_comp_con = true;
-		restoreKinematic(rbw);
 
 		rbw->ltime = startframe;
 		if ((rbw->object_changed))
@@ -3128,6 +3126,10 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
 		rbw->ltime = ctime;
 		return;
 	}
+	else if (rbw->ltime == startframe)
+	{
+		restoreKinematic(rbw);
+	}
 
 	/* advance simulation, we can only step one frame forward */
 	if (ctime == rbw->ltime + 1 && !(cache->flag & PTCACHE_BAKED)) {
diff --git a/source/blender/makesdna/DNA_rigidbody_types.h b/source/blender/makesdna/DNA_rigidbody_types.h
index 38a6617..019f370 100644
--- a/source/blender/makesdna/DNA_rigidbody_types.h
+++ b/source/blender/makesdna/DNA_rigidbody_types.h
@@ -364,7 +364,9 @@ typedef enum eRigidBodyCon_Flag {
 	RBC_FLAG_USE_SPRING_Z				= (1 << 13),
 	/* motors */
 	RBC_FLAG_USE_MOTOR_LIN				= (1 << 14),
-	RBC_FLAG_USE_MOTOR_ANG				= (1 << 15)
+	RBC_FLAG_USE_MOTOR_ANG				= (1 << 15),
+	/* prevent multiple removal and crash with kinematic deactivation */
+	RBC_FLAG_USE_KINEMATIC_DEACTIVATION = (1 << 16),
 } eRigidBodyCon_Flag;
 
 /* ******************************** */
diff --git a/source/blender/modifiers/intern/MOD_fracture.c b/source/blender/modifiers/intern/MOD_fracture.c
index 7474a8f..45d6362 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -100,7 +100,7 @@ static void initData(ModifierData *md)
 	fmd->contact_dist = 1.0f;
 	fmd->use_mass_dependent_thresholds = false;
 	fmd->explo_shared = false;
-	fmd->constraint_limit = 0;
+	fmd->constraint_limit = 50;
 	fmd->breaking_distance = 0;
 	fmd->breaking_angle = 0;
 	fmd->breaking_percentage = 0;     /* disable by default*/




More information about the Bf-blender-cvs mailing list