Thread: eXtremely strange problem with amount indicator

  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158

    Exclamation 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.

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    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!

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Buffer overflow perhaps? Where is quadEx declared, and is its size at least 51?
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    51
    Have you stepped through it to see it change there? I see no reason why the value of quads should change to 3....

  5. #5
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    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?

  6. #6
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    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.
    Last edited by Yarin; 10-25-2007 at 02:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange problem
    By G4B3 in forum C Programming
    Replies: 6
    Last Post: 05-14-2008, 02:07 PM
  2. Strange problem with classes in header files
    By samGwilliam in forum C++ Programming
    Replies: 2
    Last Post: 02-29-2008, 04:55 AM
  3. a strange problem :(
    By angeljicu in forum C Programming
    Replies: 2
    Last Post: 01-08-2003, 09:27 PM
  4. A strange problem with creating a file
    By Waldo2k2 in forum C++ Programming
    Replies: 4
    Last Post: 05-27-2002, 03:42 PM
  5. Strange problem with fts_open call
    By jhopper in forum C Programming
    Replies: 0
    Last Post: 02-26-2002, 12:01 AM