Commit: 748ada90b5fb56f9a67a3ab4de76c17f90c98de7
Author: Martin Felke
Date:   Wed Feb 14 21:04:00 2018 +0100
Branches: fracture_modifier
https://developer.blender.org/rB748ada90b5fb56f9a67a3ab4de76c17f90c98de7

further constraint related crash fixes

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

M       source/blender/blenkernel/intern/fracture.c
M       source/blender/blenkernel/intern/rigidbody.c

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

diff --git a/source/blender/blenkernel/intern/fracture.c 
b/source/blender/blenkernel/intern/fracture.c
index 0e80b6a6630..fd8ef26a6bb 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -2645,6 +2645,22 @@ void BKE_free_constraints(FractureModifierData *fmd)
 
        for (mi = fmd->meshIslands.first; mi; mi = mi->next) {
                if (mi->participating_constraints != NULL && 
mi->participating_constraint_count > 0) {
+                       int i = 0;
+
+                       for (i = 0; i < mi->participating_constraint_count; i++)
+                       {
+                               RigidBodyShardCon *con = 
mi->participating_constraints[i];
+                               if (con) {
+                                       if (con->mi1 == mi) {
+                                               con->mi1 = NULL;
+                                       }
+
+                                       if (con->mi2 == mi) {
+                                               con->mi2 = NULL;
+                                       }
+                               }
+                       }
+
                        MEM_freeN(mi->participating_constraints);
                        mi->participating_constraints = NULL;
                        mi->participating_constraint_count = 0;
@@ -3647,7 +3663,12 @@ static void remove_participants(RigidBodyShardCon* con, 
MeshIsland *mi)
        RigidBodyShardCon **cons;
        /* Probably wrong, would need to shrink array size... listbase would 
have been better here */
        /* info not necessary so omit */
-       int count = mi->participating_constraint_count;
+       int count = 0;
+
+       if (!mi)
+               return;
+
+       count = mi->participating_constraint_count;
 
        if (count > 1)
        {
diff --git a/source/blender/blenkernel/intern/rigidbody.c 
b/source/blender/blenkernel/intern/rigidbody.c
index d0e37d7afc9..454f3f74e73 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -2566,7 +2566,10 @@ static bool isModifierActive(FractureModifierData *rmd) {
 static void calc_dist_angle(RigidBodyShardCon *con, float *dist, float *angle, 
bool exact)
 {
        float q1[4], q2[4], qdiff[4], axis[3];
-       if ((con->mi1->rigidbody == NULL) || (con->mi2->rigidbody == NULL)) {
+
+       if (con == NULL || con->mi1 == NULL || con->mi2 == NULL ||
+           con->mi1->rigidbody == NULL || con->mi2->rigidbody == NULL)
+       {
                *dist = 0;
                *angle = 0;
                return;
@@ -5026,11 +5029,17 @@ static void handle_solver_iterations(RigidBodyWorld 
*rbw, FractureModifierData *
                iterations = rbw->num_solver_iterations;
        }
        else {
-               if ((rbsc->mi1->particle_index != -1) && 
(rbsc->mi1->particle_index == rbsc->mi2->particle_index)) {
-                       iterations = fmd->cluster_solver_iterations_override;
+               if (rbsc && rbsc->mi1 && rbsc->mi2)
+               {
+                       if ((rbsc->mi1->particle_index != -1) && 
(rbsc->mi1->particle_index == rbsc->mi2->particle_index)) {
+                               iterations = 
fmd->cluster_solver_iterations_override;
+                       }
+                       else {
+                               iterations = fmd->solver_iterations_override;
+                       }
                }
                else {
-                       iterations = fmd->solver_iterations_override;
+                       iterations = rbw->num_solver_iterations;
                }
        }
 
@@ -5171,6 +5180,10 @@ static bool do_update_modifier(Scene* scene, Object* ob, 
RigidBodyWorld *rbw, bo
 
                for (rbsc = fmd->meshConstraints.first; rbsc; rbsc = 
rbsc->next) {
 
+                       //sanity check
+                       if (!rbsc || !rbsc->mi1 || !rbsc->mi2)
+                               continue;
+
                        if (rebuild)
                        {
                                rbsc->start_angle = 0.0f;

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to