Fix T46232: Boids crash w/ random rule selection
authorCampbell Barton <ideasman42@gmail.com>
Thu, 24 Sep 2015 06:07:30 +0000 (16:07 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 24 Sep 2015 06:07:30 +0000 (16:07 +1000)
source/blender/blenkernel/intern/boids.c

index 489e26c5cbe2fc2b1ef0b2a24e045b8bd0e9daad..d765dff132fdb2ce4f1efdf18f3bbf93f1d73a00 100644 (file)
@@ -1006,9 +1006,11 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa)
                case eBoidRulesetType_Random:
                {
                        /* use random rule for each particle (always same for same particle though) */
-                       rule = BLI_findlink(&state->rules, rand % BLI_listbase_count(&state->rules));
-
-                       apply_boid_rule(bbd, rule, &val, pa, -1.0);
+                       const int n = BLI_listbase_count(&state->rules);
+                       if (n) {
+                               rule = BLI_findlink(&state->rules, rand % n);
+                               apply_boid_rule(bbd, rule, &val, pa, -1.0);
+                       }
                        break;
                }
                case eBoidRulesetType_Average: