Fix T53832: Particle weight paint crash

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.
This commit is contained in:
Campbell Barton 2018-01-19 12:07:14 +11:00
parent 42a562496b
commit 2b9fb723ed
Notes: blender-bot 2023-02-14 06:45:14 +01:00
Referenced by issue #53832, Particle weight paint crash
Referenced by issue #53683, 2.79a release
1 changed files with 18 additions and 10 deletions

View 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) {