Omnimaga

Calculator Community => TI Calculators => Calculator C => Topic started by: Matrefeytontias on June 02, 2013, 12:36:19 pm

Title: [Ndless] Weird error
Post by: Matrefeytontias on June 02, 2013, 12:36:19 pm
Hallaw,

I'm stuck with a weird error when programming with Ndless. The emulated Ti-Nspire CX (not sure if CAS) crashes when executing :
Code: [Select]
int* D3_sortFaces(Vertex *vertexTable, Vertex camera, int **faces, int numberOfFaces, int *verticesPerFace)
{
int i, j, flag, intermediate;
char *order;
int *zAverage;

order = malloc(numberOfFaces * sizeof(char));
if(order == NULL)
{
printf("error with order");
return NULL;
}

zAverage = malloc(numberOfFaces * sizeof(int));
if(zAverage == NULL)
{
free(order);
printf("error with zAverage");
return NULL;
}

for(i = 0; i < numberOfFaces; i++)
{
order[i] = i;
zAverage[i] = 0;
for(j = 0; j < verticesPerFace[i]; j++)
{
printf("%d,%d\n",i,j);
zAverage[i] += vertexTable[faces[i][j]].z - camera.z; // crashes here
}
zAverage[i] /= verticesPerFace[i];
}
printf("zAverage passed");
// etc
Given :
Code: [Select]
char faces[6][4] = { {0, 1, 2, 3}, {4, 5, 6, 7}, {0, 4, 7, 3}, {3, 2, 6, 7}, {0, 1, 5, 4}, {1, 5, 6, 2 } };
char *order;
int vpf[6] = { 4, 4, 4, 4, 4, 4 };


// ...
// rotated is a 8 elements-large table of bunches of 3 values
order = D3_sortFaces(rotated, (Vertex){0, 0, -150}, faces, 6, vpf);

I don't know if you understand well, but I don't want to release a complete source for now :/

What this does is that it displays "0,0", \n then "Reset" and → crash.

If you have any idea of what's wrong, please tell me :(
Title: Re: [Ndless] Weird error
Post by: Levak on June 02, 2013, 01:19:08 pm
Try to put globals (faces, order, vpf) as static.
Also, avoid as possible globals.

Edit : wait, no, your data is wrong, you only have 6 points and face indexes are 0->7 (8 points)
Title: Re: [Ndless] Weird error
Post by: Matrefeytontias on June 02, 2013, 02:44:58 pm
Nvm, I found a work-around. This'll do.