Fix T53823: Particle weight brush crash
authorCampbell Barton <ideasman42@gmail.com>
Fri, 19 Jan 2018 01:25:09 +0000 (12:25 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 19 Jan 2018 01:25:09 +0000 (12:25 +1100)
Entering particle edit mode w/ the weight brush enabled crashed
on non-hair particle systems.

source/blender/blenkernel/intern/particle.c

index ba75760c07aa17439086f41d3280f31ccf2296ff..26e7562590d5ee661ad2c813bdc46d5273f15028 100644 (file)
@@ -2794,7 +2794,9 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf
 
        /* frs_sec = (psys || edit->pid.flag & PTCACHE_VEL_PER_SEC) ? 25.0f : 1.0f; */ /* UNUSED */
 
-       if (pset->brushtype == PE_BRUSH_WEIGHT) {
+       const bool use_weight = (pset->brushtype == PE_BRUSH_WEIGHT) && (psys != NULL) && (psys->particles != NULL);
+
+       if (use_weight) {
                ; /* use weight painting colors now... */
        }
        else {
@@ -2824,7 +2826,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf
 
 
                /* should init_particle_interpolation set this ? */
-               if (pset->brushtype == PE_BRUSH_WEIGHT) {
+               if (use_weight) {
                        pind.hkey[0] = NULL;
                        /* pa != NULL since the weight brush is only available for hair */
                        pind.hkey[0] = pa->hair;
@@ -2885,7 +2887,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf
                        }
 
                        /* selection coloring in edit mode */
-                       if (pset->brushtype == PE_BRUSH_WEIGHT) {
+                       if (use_weight) {
                                if (k == 0) {
                                        weight_to_rgb(ca->col, pind.hkey[1]->weight);
                                }