ClosthCollision: fully avoid computing BVHTree when we have no collision objects...
authorBastien Montagne <montagne29@wanadoo.fr>
Mon, 3 Sep 2018 15:32:46 +0000 (17:32 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Mon, 3 Sep 2018 15:32:46 +0000 (17:32 +0200)
Followup to rBc6bbe6c5aac29, much more elegant solution to the problem. ;)

source/blender/blenkernel/intern/collision.c

index 65c84187307283f59b085518c2bc2cb4107bba9d..1df749ee8420bdecb55faac3f403d6ec8f91f4e9 100644 (file)
@@ -1339,6 +1339,14 @@ void cloth_find_point_contacts(Object *ob, ClothModifierData *clmd, float step,
        // static collisions
        ////////////////////////////////////////////////////////////
 
+       /* Check we do have collision objects to test against, before doing anything else. */
+       collobjs = get_collisionobjects(clmd->scene, ob, clmd->coll_parms->group, &numcollobj, eModifierType_Collision);
+       if (!collobjs) {
+               *r_collider_contacts = NULL;
+               *r_totcolliders = 0;
+               return;
+       }
+
        // create temporary cloth points bvh
        cloth_bvh = BLI_bvhtree_new(mvert_num, max_ff(clmd->coll_parms->epsilon, clmd->coll_parms->distance_repel), 4, 6);
        /* fill tree */
@@ -1353,14 +1361,6 @@ void cloth_find_point_contacts(Object *ob, ClothModifierData *clmd, float step,
        /* balance tree */
        BLI_bvhtree_balance(cloth_bvh);
 
-       collobjs = get_collisionobjects(clmd->scene, ob, clmd->coll_parms->group, &numcollobj, eModifierType_Collision);
-       if (!collobjs) {
-               *r_collider_contacts = NULL;
-               *r_totcolliders = 0;
-               BLI_bvhtree_free(cloth_bvh);
-               return;
-       }
-
        /* move object to position (step) in time */
        for (i = 0; i < numcollobj; i++) {
                Object *collob= collobjs[i];