Can you have a look. Value of my object is being set to zero somewhere!

boyfarrell

Registered
Hello everybody,

It's late here an I need to go to bed, so maybe that's why this has completely confused me.

I have a few for loops here that, (i) produces a Vector class instance, (ii) do some maths then, (iii) store the Vector (now containing numbers) in a C-Array of Vectors. Sounds easy.

But when I try to use those numbers outside the for loop I find they are all set to zero. As somebody said a piece of code is worth a 1e3 words so here goes:

Code:
-(void) algo
{
#define ptsL 5
#define ptsW 5
#define ptsD 5

     //create a C-Array of Vector Objects
	Vector *term2[ptsL][ptsW][ptsD][ptsD];
     
      //some constant called ang
	double ang = pow((cos([self theta]/2)),2);

	//This code flips the an NSMutableArray instance variable
	NSMutableArray *reversePtsinD;
	reversePtsinD = [NSMutableArray arrayWithCapacity: ptsD];
	reversePtsinD = [[[self z] reverseObjectEnumerator] allObjects];
	
	unsigned int i,j,q,qq;				
	for (qq=0; qq < ptsD; qq++)
		for (q=0; q < (ptsD-qq); q++)
			for (j=0; j < ptsW; j++)
				for (i=0; i < ptsL; i++)
				{
                            //alloc and init the Vector before use
					term2[i][j][q][qq] = [[Vector alloc] init];
			
                 //number crunching bit
			term2[i][j][q][qq] = [
				
				[ ([[self nsaAsVector] divideBy: ang]) multiplyBy: ([[reversePtsinD objectAtIndex:qq] doubleValue]-[self z:q]) ]
									
								vSinh];
			

			//print in the first interation - THIS SHOWS NUMBERS
			if(i == j && j == q && q == qq && qq == 0)
			{
				[term2[0][0][0][0] print];
				printf("\nretainCount (in loop) = %d\n",[term2[0][0][0][0] retainCount]);
				
			}
			
			//print in the last iteration -  THIS SHOWS ZEROS
			if(i == 4 && j == 4 && q == 0 && qq == 4)
			{
				printf("\nfinal loop iteration\n");
				[term2[0][0][0][0] print];
				printf("\nretainCount (in loop) = %d\n",[term2[0][0][0][0] retainCount]);
			}
			
			
			
		}
                       //THIS SHOWS ZEROS
 				[term2[0][0][0][0] print];
				printf("\nretainCount (out of loop) = %d\n",[term2[0][0][0][0] retainCount]);
}
 
Back
Top