Fix T46382: Crash sharing particle system with clump or rough curves
Made those curves local to thread evaluation now, so there is no threading conflict accessing them from evaluation threads anymore.
This commit is contained in:
parent
4ceea37db4
commit
6290df0cf4
Notes:
blender-bot
2023-02-14 08:49:53 +01:00
Referenced by issue #46382, Trying to create hair with particles makes Blender crash
|
@ -156,6 +156,9 @@ typedef struct ParticleThreadContext {
|
|||
float *vg_length, *vg_clump, *vg_kink;
|
||||
float *vg_rough1, *vg_rough2, *vg_roughe;
|
||||
float *vg_effector;
|
||||
|
||||
struct CurveMapping *clumpcurve;
|
||||
struct CurveMapping *roughcurve;
|
||||
} ParticleThreadContext;
|
||||
|
||||
typedef struct ParticleTask {
|
||||
|
|
|
@ -105,7 +105,7 @@ static void get_child_modifier_parameters(ParticleSettings *part, ParticleThread
|
|||
ChildParticle *cpa, short cpa_from, int cpa_num, float *cpa_fuv, float *orco, ParticleTexture *ptex);
|
||||
static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSettings *part, ParticleData *par,
|
||||
int child_index, int face_index, const float fw[4], float *orco, ParticleTexture *ptex, int event, float cfra);
|
||||
extern void do_child_modifiers(ParticleSimulationData *sim,
|
||||
extern void do_child_modifiers(ParticleThreadContext *ctx, ParticleSimulationData *sim,
|
||||
ParticleTexture *ptex, const float par_co[3], const float par_vel[3], const float par_rot[4], const float par_orco[3],
|
||||
ChildParticle *cpa, const float orco[3], float mat[4][4], ParticleKey *state, float t);
|
||||
|
||||
|
@ -2105,10 +2105,20 @@ static bool psys_thread_context_init_path(ParticleThreadContext *ctx, ParticleSi
|
|||
ctx->vg_effector = psys_cache_vgroup(ctx->dm, psys, PSYS_VG_EFFECTOR);
|
||||
|
||||
/* prepare curvemapping tables */
|
||||
if ((part->child_flag & PART_CHILD_USE_CLUMP_CURVE) && part->clumpcurve)
|
||||
curvemapping_changed_all(part->clumpcurve);
|
||||
if ((part->child_flag & PART_CHILD_USE_ROUGH_CURVE) && part->roughcurve)
|
||||
curvemapping_changed_all(part->roughcurve);
|
||||
if ((part->child_flag & PART_CHILD_USE_CLUMP_CURVE) && part->clumpcurve) {
|
||||
ctx->clumpcurve = curvemapping_copy(part->clumpcurve);
|
||||
curvemapping_changed_all(ctx->clumpcurve);
|
||||
}
|
||||
else {
|
||||
ctx->clumpcurve = NULL;
|
||||
}
|
||||
if ((part->child_flag & PART_CHILD_USE_ROUGH_CURVE) && part->roughcurve) {
|
||||
ctx->clumpcurve = curvemapping_copy(part->roughcurve);
|
||||
curvemapping_changed_all(ctx->roughcurve);
|
||||
}
|
||||
else {
|
||||
ctx->roughcurve = NULL;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -3890,7 +3900,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey *
|
|||
copy_particle_key(&tstate, state, 1);
|
||||
|
||||
/* apply different deformations to the child path */
|
||||
do_child_modifiers(sim, &ptex, par->co, par->vel, par->rot, par_orco, cpa, orco, hairmat, state, t);
|
||||
do_child_modifiers(NULL, sim, &ptex, par->co, par->vel, par->rot, par_orco, cpa, orco, hairmat, state, t);
|
||||
|
||||
/* try to estimate correct velocity */
|
||||
if (vel) {
|
||||
|
@ -3993,7 +4003,7 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta
|
|||
CLAMP(t, 0.0f, 1.0f);
|
||||
|
||||
unit_m4(mat);
|
||||
do_child_modifiers(sim, NULL, key1->co, key1->vel, key1->rot, par_orco, cpa, cpa->fuv, mat, state, t);
|
||||
do_child_modifiers(NULL, sim, NULL, key1->co, key1->vel, key1->rot, par_orco, cpa, cpa->fuv, mat, state, t);
|
||||
|
||||
if (psys->lattice_deform_data)
|
||||
calc_latt_deform(psys->lattice_deform_data, state->co, 1.0f);
|
||||
|
|
|
@ -43,7 +43,7 @@ void do_kink(ParticleKey *state, const float par_co[3], const float par_vel[3],
|
|||
short type, short axis, float obmat[4][4], int smooth_start);
|
||||
float do_clump(ParticleKey *state, const float par_co[3], float time, const float orco_offset[3], float clumpfac, float clumppow, float pa_clump,
|
||||
bool use_clump_noise, float clump_noise_size, CurveMapping *clumpcurve);
|
||||
void do_child_modifiers(ParticleSimulationData *sim,
|
||||
void do_child_modifiers(ParticleThreadContext *ctx, ParticleSimulationData *sim,
|
||||
ParticleTexture *ptex, const float par_co[3], const float par_vel[3], const float par_rot[4], const float par_orco[3],
|
||||
ChildParticle *cpa, const float orco[3], float mat[4][4], ParticleKey *state, float t);
|
||||
|
||||
|
@ -281,7 +281,7 @@ static void do_kink_spiral(ParticleThreadContext *ctx, ParticleTexture *ptex, co
|
|||
}
|
||||
|
||||
/* apply different deformations to the child path */
|
||||
do_child_modifiers(&ctx->sim, ptex, par_co, par_vel, par_rot, parent_orco, cpa, orco, hairmat, (ParticleKey *)key, par_time);
|
||||
do_child_modifiers(ctx, &ctx->sim, ptex, par_co, par_vel, par_rot, parent_orco, cpa, orco, hairmat, (ParticleKey *)key, par_time);
|
||||
}
|
||||
|
||||
totlen = 0.0f;
|
||||
|
@ -349,7 +349,7 @@ void psys_apply_child_modifiers(ParticleThreadContext *ctx, struct ListBase *mod
|
|||
par = (ParticleKey *)iter.parent_key;
|
||||
|
||||
/* apply different deformations to the child path */
|
||||
do_child_modifiers(&ctx->sim, ptex, par->co, par->vel, iter.parent_rotation, parent_orco, cpa, orco, hairmat, (ParticleKey *)key, iter.time);
|
||||
do_child_modifiers(ctx, &ctx->sim, ptex, par->co, par->vel, iter.parent_rotation, parent_orco, cpa, orco, hairmat, (ParticleKey *)key, iter.time);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -664,15 +664,22 @@ static void do_rough_curve(const float loc[3], float mat[4][4], float time, floa
|
|||
madd_v3_v3fl(state->co, mat[2], fac * rough[2]);
|
||||
}
|
||||
|
||||
void do_child_modifiers(ParticleSimulationData *sim, ParticleTexture *ptex, const float par_co[3], const float par_vel[3], const float par_rot[4], const float par_orco[3],
|
||||
void do_child_modifiers(ParticleThreadContext *ctx, ParticleSimulationData *sim, ParticleTexture *ptex,
|
||||
const float par_co[3], const float par_vel[3], const float par_rot[4], const float par_orco[3],
|
||||
ChildParticle *cpa, const float orco[3], float mat[4][4], ParticleKey *state, float t)
|
||||
{
|
||||
ParticleSettings *part = sim->psys->part;
|
||||
CurveMapping *clumpcurve = (part->child_flag & PART_CHILD_USE_CLUMP_CURVE) ? part->clumpcurve : NULL;
|
||||
CurveMapping *roughcurve = (part->child_flag & PART_CHILD_USE_ROUGH_CURVE) ? part->roughcurve : NULL;
|
||||
CurveMapping *clumpcurve = NULL, *roughcurve = NULL;
|
||||
int i = cpa - sim->psys->child;
|
||||
int guided = 0;
|
||||
|
||||
if (part->child_flag & PART_CHILD_USE_CLUMP_CURVE) {
|
||||
clumpcurve = (ctx != NULL) ? ctx->clumpcurve : part->clumpcurve;
|
||||
}
|
||||
if (part->child_flag & PART_CHILD_USE_ROUGH_CURVE) {
|
||||
roughcurve = (ctx != NULL) ? ctx->roughcurve : part->roughcurve;
|
||||
}
|
||||
|
||||
float kink_amp = part->kink_amp;
|
||||
float kink_amp_clump = part->kink_amp_clump;
|
||||
float kink_freq = part->kink_freq;
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
#include "BKE_boids.h"
|
||||
#include "BKE_cdderivedmesh.h"
|
||||
#include "BKE_collision.h"
|
||||
#include "BKE_colortools.h"
|
||||
#include "BKE_effect.h"
|
||||
#include "BKE_library_query.h"
|
||||
#include "BKE_particle.h"
|
||||
|
@ -511,6 +512,13 @@ void psys_thread_context_free(ParticleThreadContext *ctx)
|
|||
if (ctx->seams) MEM_freeN(ctx->seams);
|
||||
//if (ctx->vertpart) MEM_freeN(ctx->vertpart);
|
||||
BLI_kdtree_free(ctx->tree);
|
||||
|
||||
if (ctx->clumpcurve != NULL) {
|
||||
curvemapping_free(ctx->clumpcurve);
|
||||
}
|
||||
if (ctx->roughcurve != NULL) {
|
||||
curvemapping_free(ctx->roughcurve);
|
||||
}
|
||||
}
|
||||
|
||||
static void initialize_particle_texture(ParticleSimulationData *sim, ParticleData *pa, int p)
|
||||
|
|
Loading…
Reference in New Issue