[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34526] trunk/blender/source/blender: Fixing some clang reported issues in particle code.

Janne Karhu jhkarh at gmail.com
Thu Jan 27 13:21:16 CET 2011


Revision: 34526
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34526
Author:   jhk
Date:     2011-01-27 12:21:14 +0000 (Thu, 27 Jan 2011)
Log Message:
-----------
Fixing some clang reported issues in particle code.
* Not really bugs, but some code cleanup and clarification.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/particle.c
    trunk/blender/source/blender/blenkernel/intern/particle_system.c
    trunk/blender/source/blender/editors/physics/particle_edit.c

Modified: trunk/blender/source/blender/blenkernel/intern/particle.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle.c	2011-01-27 11:17:23 UTC (rev 34525)
+++ trunk/blender/source/blender/blenkernel/intern/particle.c	2011-01-27 12:21:14 UTC (rev 34526)
@@ -1469,7 +1469,7 @@
 		}
 		else {
 			VECCOPY(orco, vec);
-			if(ornor)
+			if(ornor && nor)
 				VECCOPY(ornor, nor);
 		}
 	}
@@ -1961,7 +1961,7 @@
 	{
 		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 @@
 		}
 		
 		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 @@
 {
 	ParticleThread *pthreads;
 	ParticleThreadContext *ctx;
-	/*ParticleCacheKey **cache;*/ /*UNUSED*/
 	ListBase threads;
 	int i, totchild, totparent, totthread;
 
@@ -2764,7 +2762,7 @@
 	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 @@
 		/* 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 @@
 	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 @@
 
 	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 @@
 			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;
 		}

Modified: trunk/blender/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle_system.c	2011-01-27 11:17:23 UTC (rev 34525)
+++ trunk/blender/source/blender/blenkernel/intern/particle_system.c	2011-01-27 12:21:14 UTC (rev 34526)
@@ -223,6 +223,15 @@
 			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 @@
 	BoidBrainData bbd;
 	PARTICLE_P;
 	float timestep;
-	/* current time */
-	/* float ctime; */ /*UNUSED*/
 	/* frame & time changes */
 	float dfra, dtime;
 	float birthtime, dietime;
@@ -3412,7 +3419,6 @@
 	dfra= cfra - psys->cfra;
 
 	timestep = psys_get_timestep(sim);
-	/*ctime= cfra*timestep;*/ /*UNUSED*/
 	dtime= dfra*timestep;
 
 	if(dfra<0.0){
@@ -3675,7 +3681,7 @@
 		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];

Modified: trunk/blender/source/blender/editors/physics/particle_edit.c
===================================================================
--- trunk/blender/source/blender/editors/physics/particle_edit.c	2011-01-27 11:17:23 UTC (rev 34525)
+++ trunk/blender/source/blender/editors/physics/particle_edit.c	2011-01-27 12:21:14 UTC (rev 34526)
@@ -484,13 +484,10 @@
 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 @@
 	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 @@
 	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 @@
 		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 @@
 				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));




More information about the Bf-blender-cvs mailing list