eXtremely strange problem with amount indicator

Printable View

• 10-25-2007
Yarin
eXtremely strange problem with amount indicator
Look at this section of code:
Before calling this, the varible quads is 50.
Code:

```  // Copy the wings to the other side now:   for(x = 0, bWingsOut = FALSE; x < quads; x++) {       if(quadEx[x] == XL_WING) bWingsOut = TRUE;       if(bWingsOut) {         if(quadEx[x] == XL_END) bWingsOut = FALSE;         quadEx[quads] = quadEx[x]; // THIS LINE         for(y = 0; y < 7; y++)             quad[quads][y] = quad[x][y];         quad[quads][1] = -quad[x][1];         quads++;  }  }```
After I call this, quads becomes 3. Why?? I only alter quads for the greater once!
The weird thing is, when I comment out THIS LINE, quads is what it's suppose to be.
Please help.
• 10-25-2007
Yarin
This is really strange; changing the code to
Code:

```  // Copy the wings to the other side now:   for(x = 0, bWingsOut = FALSE; x < quads; x++) {       if(quadEx[x] == XL_WING) bWingsOut = TRUE;       if(bWingsOut) {         if(quadEx[x] == XL_END) bWingsOut = FALSE;         if(quadEx[x] != XL_WING) quadEx[quads] = quadEx[x];         else z = quads;         for(y = 0; y < 7; y++)             quad[quads][y] = quad[x][y];         quad[quads][1] = -quad[x][1];         quads++;  }  }   quadEx[z] = XL_WING;```
works.
If anyone knows why it's doing this I would still like to know!
• 10-25-2007
JaWiB
Buffer overflow perhaps? Where is quadEx declared, and is its size at least 51?
• 10-25-2007
markcole
Have you stepped through it to see it change there? I see no reason why the value of quads should change to 3....
• 10-25-2007
twomers
Indeed. Have you tried printing quad's value for each iteration and seeing it change? Or does 'x<quads' only run once?

Is quad your own type? If so how do you pass into the [] operator? Reference? Do you change it?
• 10-25-2007
Yarin
This loop only runs once durring init.

I have already thought of buffer overflow, but as you can see my decs don't indicate anything of the sort.
Code:

```#define XL_VECTOR  0 #define XL_END      1 #define XL_WING    2 #define MAX_QUADS 300 float quad[MAX_QUADS][7]; int quadEx[MAX_QUADS]; int quads, x, y, z;```
EDIT:
The part that baffles me...
Like I pointed out in my 2nd post, the error only happens when I try to assign quadEx[quads] to the value 2.