From fc066a6a5d01718981c9dcae23c5f4f47f3d7b1e Mon Sep 17 00:00:00 2001 From: Janne Karhu Date: Fri, 25 Dec 2009 23:51:29 +0000 Subject: [PATCH] Fix for [#20458] Segmentation fault when trying to enable Hair dynamics * The hair mesh vertex index was stored as a short, but vertex counts can easily go higher than what fits in a short so changed this to an int. * Also removed particle life looping, which didn't work correctly anyways. Similar functionality will become available when I get to recoding reactor particles into a better system. --- source/blender/blenkernel/intern/particle.c | 2 +- .../blenkernel/intern/particle_system.c | 46 ++++++------------- source/blender/makesdna/DNA_particle_types.h | 5 +- source/blender/makesrna/intern/rna_particle.c | 11 ----- 4 files changed, 16 insertions(+), 48 deletions(-) diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index b19b0f9fa20..992f63520ab 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -4069,7 +4069,7 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta else{ if(cpa){ ParticleKey *key1; - float t = (cfra - pa->time + pa->loop * pa->lifetime) / pa->lifetime; + float t = (cfra - pa->time) / pa->lifetime; key1=&pa->state; offset_child(cpa, key1, state, part->childflat, part->childrad); diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index ce595bb280d..9882bfea137 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -389,7 +389,7 @@ static void distribute_particles_in_grid(DerivedMesh *dm, ParticleSystem *psys) pa->fuv[1]=min[1]+(float)j*d; pa->fuv[2]=min[2]+(float)k*d; pa->flag |= PARS_UNEXIST; - pa->loop=0; /* abused in volume calculation */ + pa->hair_index=0; /* abused in volume calculation */ } } } @@ -451,7 +451,7 @@ static void distribute_particles_in_grid(DerivedMesh *dm, ParticleSystem *psys) if(from==PART_FROM_FACE) (pa+(int)(lambda*size[a])*a0mul)->flag &= ~PARS_UNEXIST; else /* store number of intersections */ - (pa+(int)(lambda*size[a])*a0mul)->loop++; + (pa+(int)(lambda*size[a])*a0mul)->hair_index++; } if(mface->v4){ @@ -461,20 +461,20 @@ static void distribute_particles_in_grid(DerivedMesh *dm, ParticleSystem *psys) if(from==PART_FROM_FACE) (pa+(int)(lambda*size[a])*a0mul)->flag &= ~PARS_UNEXIST; else - (pa+(int)(lambda*size[a])*a0mul)->loop++; + (pa+(int)(lambda*size[a])*a0mul)->hair_index++; } } } if(from==PART_FROM_VOLUME){ - int in=pa->loop%2; - if(in) pa->loop++; + int in=pa->hair_index%2; + if(in) pa->hair_index++; for(i=0; iloop%2) + if(in || (pa+i*a0mul)->hair_index%2) (pa+i*a0mul)->flag &= ~PARS_UNEXIST; /* odd intersections == in->out / out->in */ /* even intersections -> in stays same */ - in=(in + (pa+i*a0mul)->loop) % 2; + in=(in + (pa+i*a0mul)->hair_index) % 2; } } } @@ -1584,7 +1584,7 @@ void initialize_particle(ParticleSimulationData *sim, ParticleData *pa, int p) pa->flag &= ~PARS_UNEXIST; } - pa->loop=0; + pa->hair_index=0; /* we can't reset to -1 anymore since we've figured out correct index in distribute_particles */ /* usage other than straight after distribute has to handle this index by itself - jahka*/ //pa->num_dmcache = DMCACHE_NOTFOUND; /* assume we dont have a derived mesh face */ @@ -3215,14 +3215,6 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) pa->size *= 1.0f - part->randsize * PSYS_FRAND(p + 1); reset_particle(sim, pa, dtime, cfra); - - if(cfra > pa->time && part->flag & PART_LOOP && part->type!=PART_HAIR){ - pa->loop = (short)((cfra-pa->time)/pa->lifetime); - pa->alive = PARS_UNBORN; - } - else{ - pa->loop = 0; - } } if(vg_size) @@ -3276,7 +3268,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) //if(psys->reactevents.first && ELEM(pa->alive,PARS_DEAD,PARS_KILLED)==0) // react_to_events(psys,p); - birthtime = pa->time + pa->loop * pa->lifetime; + birthtime = pa->time; dietime = birthtime + pa->lifetime; pa_dfra = dfra; @@ -3335,15 +3327,8 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) if(pa->alive == PARS_DYING){ //push_reaction(ob,psys,p,PART_EVENT_DEATH,&pa->state); - if(part->flag & PART_LOOP && part->type!=PART_HAIR){ - pa->loop++; - reset_particle(sim, pa, 0.0, cfra); - pa->alive=PARS_ALIVE; - } - else{ - pa->alive=PARS_DEAD; - pa->state.time=pa->dietime; - } + pa->alive=PARS_DEAD; + pa->state.time=pa->dietime; } else pa->state.time=cfra; @@ -3394,13 +3379,8 @@ static void cached_step(ParticleSimulationData *sim, float cfra) psys->lattice= psys_get_lattice(sim); - if(part->flag & PART_LOOP && part->type!=PART_HAIR) - pa->loop = (short)((cfra - pa->time) / pa->lifetime); - else - pa->loop = 0; - - birthtime = pa->time + pa->loop * pa->lifetime; - dietime = birthtime + (1 + pa->loop) * (pa->dietime - pa->time); + birthtime = pa->time; + dietime = pa->dietime; /* update alive status and push events */ if(pa->time > cfra) { diff --git a/source/blender/makesdna/DNA_particle_types.h b/source/blender/makesdna/DNA_particle_types.h index 81510ef96a3..abcdbcefc0f 100644 --- a/source/blender/makesdna/DNA_particle_types.h +++ b/source/blender/makesdna/DNA_particle_types.h @@ -109,10 +109,9 @@ typedef struct ParticleData { float size; /* size and multiplier so that we can update size when ever */ + int hair_index; short flag; short alive; /* the life state of a particle */ - short loop; /* how many times particle life has looped */ - short hair_index; } ParticleData; typedef struct ParticleSettings { @@ -261,7 +260,7 @@ typedef struct ParticleSystem{ /* note, make sure all (runtime) are NULL's in #define PART_REACT_STA_END 1 #define PART_REACT_MULTIPLE 2 -#define PART_LOOP 4 +//#define PART_LOOP 4 /* not used anymore */ /* for dopesheet */ #define PART_DS_EXPAND 8 diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c index c5b1aafb1a3..543965a337e 100644 --- a/source/blender/makesrna/intern/rna_particle.c +++ b/source/blender/makesrna/intern/rna_particle.c @@ -814,11 +814,6 @@ static void rna_def_particle(BlenderRNA *brna) RNA_def_property_enum_items(prop, alive_items); RNA_def_property_ui_text(prop, "Alive State", ""); - prop= RNA_def_property(srna, "loop", PROP_INT, PROP_NONE); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); - //TODO: bounds - RNA_def_property_ui_text(prop, "Loop", "How may times the particle life has looped"); - // short rt2; } @@ -978,12 +973,6 @@ static void rna_def_particle_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Multi React", "React multiple times."); RNA_def_property_update(prop, 0, "rna_Particle_reset"); - prop= RNA_def_property(srna, "loop", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", PART_LOOP); - RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE); - RNA_def_property_ui_text(prop, "Loop", "Loop particle lives."); - RNA_def_property_update(prop, 0, "rna_Particle_reset"); - /* TODO: used somewhere? */ prop= RNA_def_property(srna, "hair_geometry", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", PART_HAIR_GEOMETRY);