Fix T53832: Particle weight paint crash
authorCampbell Barton <ideasman42@gmail.com>
Fri, 19 Jan 2018 01:07:14 +0000 (12:07 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 19 Jan 2018 01:14:53 +0000 (12:14 +1100)
Drawing hair weights read before the hair array start.
This code could be improved since it currently copy-pastes,
from do_particle_interpolation, but this would need larger changes.

For now just correct existing logic.

source/blender/blenkernel/intern/particle.c

index c0849e6bff4d2ccda03567a27f49244ceb482549..ba75760c07aa17439086f41d3280f31ccf2296ff 100644 (file)
@@ -2827,7 +2827,8 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf
                if (pset->brushtype == PE_BRUSH_WEIGHT) {
                        pind.hkey[0] = NULL;
                        /* pa != NULL since the weight brush is only available for hair */
-                       pind.hkey[1] = pa->hair;
+                       pind.hkey[0] = pa->hair;
+                       pind.hkey[1] = pa->hair + 1;
                }
 
 
@@ -2885,12 +2886,26 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf
 
                        /* selection coloring in edit mode */
                        if (pset->brushtype == PE_BRUSH_WEIGHT) {
-                               float t2;
-
                                if (k == 0) {
                                        weight_to_rgb(ca->col, pind.hkey[1]->weight);
                                }
                                else {
+                                       /* warning: copied from 'do_particle_interpolation' (without 'mvert' array stepping) */
+                                       float real_t;
+                                       if (result.time < 0.0f) {
+                                               real_t = -result.time;
+                                       }
+                                       else {
+                                               real_t = pind.hkey[0]->time + t * (pind.hkey[0][pa->totkey - 1].time - pind.hkey[0]->time);
+                                       }
+
+                                       while (pind.hkey[1]->time < real_t) {
+                                               pind.hkey[1]++;
+                                       }
+                                       pind.hkey[0] = pind.hkey[1] - 1;
+                                       /* end copy */
+
+
                                        float w1[3], w2[3];
                                        keytime = (t - (*pind.ekey[0]->time)) / ((*pind.ekey[1]->time) - (*pind.ekey[0]->time));
 
@@ -2899,13 +2914,6 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf
 
                                        interp_v3_v3v3(ca->col, w1, w2, keytime);
                                }
-
-                               /* at the moment this is only used for weight painting.
-                                * will need to move out of this check if its used elsewhere. */
-                               t2 = birthtime + ((float)k / (float)segments) * (dietime - birthtime);
-
-                               while (pind.hkey[1]->time < t2) pind.hkey[1]++;
-                               pind.hkey[0] = pind.hkey[1] - 1;
                        }
                        else {
                                if ((ekey + (pind.ekey[0] - point->keys))->flag & PEK_SELECT) {