Commit: 6868e0a7d92c58d4b401b70c534d78c13dbf7631
Author: Martin Felke
Date:   Wed Feb 14 20:26:07 2018 +0100
Branches: fracture_modifier
https://developer.blender.org/rB6868e0a7d92c58d4b401b70c534d78c13dbf7631

crash fix attempts

can still crash if you refracture a child object while its attached to others 
(constraints become invalid)

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

M       source/blender/blenkernel/intern/fracture.c
M       source/blender/blenkernel/intern/rigidbody.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 61c1d68b5fc..0e80b6a6630 100644
--- a/source/blender/blenkernel/intern/fracture.c
+++ b/source/blender/blenkernel/intern/fracture.c
@@ -93,6 +93,7 @@ static void parse_cell_polys(cell c, MPoly *mpoly, int 
totpoly, int *r_totloop);
 static void parse_cell_loops(cell c, MLoop *mloop, int totloop, MPoly *mpoly, 
int totpoly);
 static void parse_cell_neighbors(cell c, int *neighbors, int totpoly);
 static void fracture_collect_layers(Shard *shard, DerivedMesh *result, int 
vertstart, int polystart, int loopstart, int edgestart);
+static void remove_participants(RigidBodyShardCon *con, MeshIsland *mi);
 
 static void add_shard(FracMesh *fm, Shard *s, float mat[4][4])
 {
@@ -2653,6 +2654,9 @@ void BKE_free_constraints(FractureModifierData *fmd)
        while (fmd->meshConstraints.first) {
                rbsc = fmd->meshConstraints.first;
                BLI_remlink(&fmd->meshConstraints, rbsc);
+               remove_participants(rbsc, rbsc->mi1);
+               remove_participants(rbsc, rbsc->mi2);
+
                if (fmd->fracture_mode == MOD_FRACTURE_DYNAMIC && 
fmd->modifier.scene)
                {
                        BKE_rigidbody_remove_shard_con(fmd->modifier.scene, 
rbsc);
@@ -3397,6 +3401,21 @@ void BKE_fracture_free_mesh_island(FractureModifierData 
*rmd, MeshIsland *mi, bo
        }
 
        if (mi->participating_constraints != NULL) {
+               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;
diff --git a/source/blender/blenkernel/intern/rigidbody.c 
b/source/blender/blenkernel/intern/rigidbody.c
index 9012b236005..d0e37d7afc9 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -4235,11 +4235,11 @@ static int filterCallback(void* world, void* island1, 
void* island2, void *blend
                validOb = validOb || ((mi1 && (mi1->rigidbody->flag & 
RBO_FLAG_KINEMATIC) == 0)) || ((mi2 && mi2->rigidbody->flag & 
RBO_FLAG_KINEMATIC) == 0);
 
                validOb = validOb && (check_colgroup_ghost(ob1, ob2) && 
((check_constraint_island(fmd1, mi1, mi2) &&
-                         check_constraint_island(fmd2, mi2, mi1)) || ((ob1 != 
ob2) && !(fmd1 && fmd2))));
+                         check_constraint_island(fmd2, mi2, mi1)) || (ob1 != 
ob2)));
        }
        else {
                validOb = (check_colgroup_ghost(ob1, ob2) && 
((check_constraint_island(fmd1, mi1, mi2) &&
-                         check_constraint_island(fmd2, mi2, mi1)) || ((ob1 != 
ob2) && !(fmd1 && fmd2))));
+                         check_constraint_island(fmd2, mi2, mi1)) || (ob1 != 
ob2)));
        }
 
        return activate ? validOb : check_activate || validOb;
diff --git a/source/blender/modifiers/intern/MOD_fracture.c 
b/source/blender/modifiers/intern/MOD_fracture.c
index 67750157880..bfbd1745326 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -2616,7 +2616,7 @@ static void connect_meshislands(FractureModifierData 
*fmd, MeshIsland *mi1, Mesh
                int i;
                for (i = 0; i < mi1->participating_constraint_count; i++) {
                        con = mi1->participating_constraints[i];
-                       if ((con->mi1 == mi2) || (con->mi2 == mi2)) {
+                       if (con && ((con->mi1 == mi2) || (con->mi2 == mi2))) {
                                con_found = true;
                                break;
                        }
@@ -2625,7 +2625,7 @@ static void connect_meshislands(FractureModifierData 
*fmd, MeshIsland *mi1, Mesh
                if (!con_found) {
                        for (i = 0; i < mi2->participating_constraint_count; 
i++) {
                                con = mi2->participating_constraints[i];
-                               if ((con->mi1 == mi1) || (con->mi2 == mi1)) {
+                               if (con && ((con->mi1 == mi1) || (con->mi2 == 
mi1))) {
                                        con_found = true;
                                        break;
                                }

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

Reply via email to