Author Topic: [Ndless] Weird error  (Read 2695 times)

0 Members and 1 Guest are viewing this topic.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
[Ndless] Weird error
« 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 :(
« Last Edit: June 02, 2013, 12:38:04 pm by Matrefeytontias »

Offline Levak

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +208/-39
    • View Profile
    • My website
Re: [Ndless] Weird error
« Reply #1 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)
« Last Edit: June 02, 2013, 01:23:03 pm by Levak »
I do not get mad at people, I just want them to learn the way I learnt.
My website - TI-Planet - iNspired-Lua

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Ndless] Weird error
« Reply #2 on: June 02, 2013, 02:44:58 pm »
Nvm, I found a work-around. This'll do.