Fix for [#20458] Segmentation fault when trying to enable Hair dynamics
authorJanne Karhu <jhkarh@gmail.com>
Fri, 25 Dec 2009 23:51:29 +0000 (23:51 +0000)
committerJanne Karhu <jhkarh@gmail.com>
Fri, 25 Dec 2009 23:51:29 +0000 (23:51 +0000)
* 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
source/blender/blenkernel/intern/particle_system.c
source/blender/makesdna/DNA_particle_types.h
source/blender/makesrna/intern/rna_particle.c

index b19b0f9fa20d7286c9f10c24969d989413af3340..992f63520aba3965de5239e21a222cade5ede5bb 100644 (file)
@@ -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);
index ce595bb280d017d3cda116d4d052b6387ee60658..9882bfea137b75ff42a427de1a91d0c241f722b2 100644 (file)
@@ -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; i<size[0]; i++){
-                                                       if(in || (pa+i*a0mul)->loop%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) {
index 81510ef96a3eac2121fc69f290e96a86f8c2cb95..abcdbcefc0f7e521308aa885137e4341f8a3f912 100644 (file)
@@ -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
 
index c5b1aafb1a3200a05e27cd1e759e2068f5bb2b09..543965a337ebb9b482955c36b1949abe2b1564bb 100644 (file)
@@ -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);