Fixing some clang reported issues in particle code.
authorJanne Karhu <jhkarh@gmail.com>
Thu, 27 Jan 2011 12:21:14 +0000 (12:21 +0000)
committerJanne Karhu <jhkarh@gmail.com>
Thu, 27 Jan 2011 12:21:14 +0000 (12:21 +0000)
* Not really bugs, but some code cleanup and clarification.

source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/particle_system.c
source/blender/editors/physics/particle_edit.c

index 61bedb0b2309edbd802312afda612cbe2ac1ec5e..492b78f7365aa217bd7274dc2a618889756dac9f 100644 (file)
@@ -1469,7 +1469,7 @@ void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*or
                }
                else {
                        VECCOPY(orco, vec);
-                       if(ornor)
+                       if(ornor && nor)
                                VECCOPY(ornor, nor);
                }
        }
@@ -1961,7 +1961,7 @@ static void do_kink(ParticleKey *state, ParticleKey *par, float *par_rot, float
        {
                float y_vec[3]={0.f,1.f,0.f};
                float z_vec[3]={0.f,0.f,1.f};
-               float vec_one[3], radius, state_co[3];
+               float vec_one[3], state_co[3];
                float inp_y, inp_z, length;
 
                if(par_rot) {
@@ -1970,7 +1970,6 @@ static void do_kink(ParticleKey *state, ParticleKey *par, float *par_rot, float
                }
                
                mul_v3_fl(par_vec, -1.f);
-               radius= normalize_v3_v3(vec_one, par_vec);
 
                inp_y=dot_v3v3(y_vec, vec_one);
                inp_z=dot_v3v3(z_vec, vec_one);
@@ -2745,7 +2744,6 @@ void psys_cache_child_paths(ParticleSimulationData *sim, float cfra, int editupd
 {
        ParticleThread *pthreads;
        ParticleThreadContext *ctx;
-       /*ParticleCacheKey **cache;*/ /*UNUSED*/
        ListBase threads;
        int i, totchild, totparent, totthread;
 
@@ -2764,7 +2762,7 @@ void psys_cache_child_paths(ParticleSimulationData *sim, float cfra, int editupd
        totparent= ctx->totparent;
 
        if(editupdate && sim->psys->childcache && totchild == sim->psys->totchildcache) {
-               /*cache = sim->psys->childcache;*/ /*UNUSED*/
+               ; /* just overwrite the existing cache */
        }
        else {
                /* clear out old and create new empty path cache */
@@ -3102,6 +3100,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf
                /* should init_particle_interpolation set this ? */
                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;
                }
 
@@ -3957,7 +3956,6 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey *
        float t, frs_sec = sim->scene->r.frs_sec;
        float co[3], orco[3];
        float hairmat[4][4];
-       /*int totparent = 0;*/ /*UNUSED*/
        int totpart = psys->totpart;
        int totchild = psys->totchild;
        short between = 0, edit = 0;
@@ -3967,11 +3965,8 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey *
 
        float *cpa_fuv; int cpa_num; short cpa_from;
 
-       //if(psys_in_edit_mode(scene, psys)){
-       //      if((psys->edit_path->flag & PSYS_EP_SHOW_CHILD)==0)
-       //              totchild=0;
-       //      edit=1;
-       //}
+       /* initialize keys to zero */
+       memset(keys, 0, 4*sizeof(ParticleKey));
 
        t=state->time;
        CLAMP(t, 0.0, 1.0);
@@ -4013,12 +4008,6 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey *
                        t = psys_get_child_time(psys, cpa, -state->time, NULL, NULL);
                
                if(totchild && part->from!=PART_FROM_PARTICLE && part->childtype==PART_CHILD_FACES){
-#if 0          /* totparent is UNUSED */
-                       totparent=(int)(totchild*part->parents*0.3);
-                       
-                       if(G.rendering && part->child_nbr && part->ren_child_nbr)
-                               totparent*=(float)part->child_nbr/(float)part->ren_child_nbr;
-#endif
                        /* part->parents could still be 0 so we can't test with totparent */
                        between=1;
                }
index 62bfde601f617f55497cd75dfb37920cb38c6d8c..e35504d73d7c7adae85ec6373020776491be1e14 100644 (file)
@@ -223,6 +223,15 @@ static void realloc_particles(ParticleSimulationData *sim, int new_totpart)
                        newpars= MEM_callocN(totpart*sizeof(ParticleData), "particles");
                        if(psys->part->phystype == PART_PHYS_BOIDS)
                                newboids= MEM_callocN(totpart*sizeof(BoidParticle), "boid particles");
+
+                       if(ELEM(NULL, newpars, newboids)) {
+                                /* allocation error! */
+                               if(newpars)
+                                       MEM_freeN(newpars);
+                               if(newboids)
+                                       MEM_freeN(newboids);
+                               return;
+                       }
                }
        
                if(psys->particles) {
@@ -3402,8 +3411,6 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
        BoidBrainData bbd;
        PARTICLE_P;
        float timestep;
-       /* current time */
-       /* float ctime; */ /*UNUSED*/
        /* frame & time changes */
        float dfra, dtime;
        float birthtime, dietime;
@@ -3412,7 +3419,6 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
        dfra= cfra - psys->cfra;
 
        timestep = psys_get_timestep(sim);
-       /*ctime= cfra*timestep;*/ /*UNUSED*/
        dtime= dfra*timestep;
 
        if(dfra<0.0){
@@ -3675,7 +3681,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra))
                if( fluidmd && fluidmd->fss) { 
                        FluidsimSettings *fss= fluidmd->fss;
                        ParticleSettings *part = psys->part;
-                       ParticleData *pa=0;
+                       ParticleData *pa=NULL;
                        const char *suffix  = "fluidsurface_particles_####";
                        const char *suffix2 = ".gz";
                        char filename[256];
index 93e652023cf42309e501683210bcec99cbfb516e..5cf6864cdc82216659813c1ac0f5ef7edab1791f 100644 (file)
@@ -484,13 +484,10 @@ static int key_inside_test(PEData *data, float co[3])
 static int point_is_selected(PTCacheEditPoint *point)
 {
        KEY_K;
-       int sel;
 
        if(point->flag & PEP_HIDE)
                return 0;
 
-       sel= 0;
-
        LOOP_SELECTED_KEYS {
                return 1;
        }
@@ -773,6 +770,9 @@ static void PE_mirror_particle(Object *ob, DerivedMesh *dm, ParticleSystem *psys
        if(!mpa) {
                if(!edit->mirror_cache)
                        PE_update_mirror_cache(ob, psys);
+               
+               if(!edit->mirror_cache)
+                       return; /* something went wrong! */
 
                mi= edit->mirror_cache[i];
                if(mi == -1)
@@ -847,6 +847,9 @@ static void PE_apply_mirror(Object *ob, ParticleSystem *psys)
        if(!edit->mirror_cache)
                PE_update_mirror_cache(ob, psys);
 
+       if(!edit->mirror_cache)
+               return; /* something went wrong */
+
        /* we delay settings the PARS_EDIT_RECALC for mirrored particles
         * to avoid doing mirror twice */
        LOOP_POINTS {
@@ -2080,6 +2083,15 @@ static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror)
                if(new_totpart) {
                        npa= new_pars= MEM_callocN(new_totpart * sizeof(ParticleData), "ParticleData array");
                        npoint= new_points= MEM_callocN(new_totpart * sizeof(PTCacheEditPoint), "PTCacheEditKey array");
+
+                       if(ELEM(NULL, new_pars, new_points)) {
+                                /* allocation error! */
+                               if(new_pars)
+                                       MEM_freeN(new_pars);
+                               if(new_points)
+                                       MEM_freeN(new_points);
+                               return 0;
+                       }
                }
 
                pa= psys->particles;
@@ -3246,14 +3258,12 @@ static int brush_add(PEData *data, short number)
                                ParticleKey key3[3];
                                KDTreeNearest ptn[3];
                                int w, maxw;
-                               float maxd, mind, dd, totw=0.0, weight[3];
+                               float maxd, totw=0.0, weight[3];
 
                                psys_particle_on_dm(psmd->dm,psys->part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co1,0,0,0,0,0);
                                maxw= BLI_kdtree_find_n_nearest(tree,3,co1,NULL,ptn);
 
                                maxd= ptn[maxw-1].dist;
-                               mind= ptn[0].dist;
-                               dd= maxd - mind;
                                
                                for(w=0; w<maxw; w++) {
                                        weight[w]= (float)pow(2.0, (double)(-6.0f * ptn[w].dist / maxd));