Results 1 to 9 of 9

Thread: Values randomly changing to zero!!

  1. #1

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Unhappy Values randomly changing to zero!!

    Ok, I've got a class as shown below (using a struct, also shown), the important bit is the function 'CreateTriabglePolys':

    Code:
    struct CUSTOMVERTEX
    {
    	float x,y,z; //The absolute 3D position for this vertex (not transformed)
    	DWORD colour; //The colour of this vertex
    };
    
    class SquarePoly
    {
    	CUSTOMVERTEX Corners[3];
    public:
        SquarePoly(float x1, float y1, float z1,DWORD colour1,
                           float x2, float y2, float z2,DWORD colour2,
                           float x3, float y3, float z3,DWORD colour3,
                           float x4, float y4, float z4,DWORD colour4)
        {
            Corners[0].x = x1;//Top-Left
            Corners[0].y = y1;
            Corners[0].z = z1;
            Corners[0].colour = colour1;
            Corners[1].x = x2;//Top-Right
            Corners[1].y = y2;
            Corners[1].z = z2;
            orners[1].colour = colour2;
            Corners[2].x = x3;//Bottom-Right
            Corners[2].y = y3;
            Corners[2].z = z3;
            Corners[2].colour = colour3;
            Corners[3].x = x4;//Bottom-Left
            Corners[3].y = y4;
            Corners[3].z = z4;
            Corners[3].colour = colour4;
        };
        SquarePoly(){};
        void CreateTrianglePolys(CUSTOMVERTEX *Vertices,const int Start)
        {
            Vertices[Start] = Corners[0];
            Vertices[Start+1] = Corners[1];
            Vertices[Start+2] = Corners[2];
    
            Vertices[Start+3] = Corners[0];
            Vertices[Start+4] = Corners[2];
            Vertices[Start+5] = Corners[3];
        };
    };
    I'm calling it in a loop with the code below:

    Code:
    CUSTOMVERTEX Vertices[TERRAINWIDTH*TERRAINDEPTH*2*3-1];//2 = # of triangle to represent a square, 3 = a vertices of a triangle
    for(i=0;i<=TERRAINWIDTH;i++)
    {
        for(j=0;j<=TERRAINDEPTH;j++)
        {
            sqPolygons[i][j].CreateTrianglePolys(Vertices,VertexCount);
            VertexCount +=2;
        }
    }
    I've added watches to i, j and VertexCount (which is passed as a const!!) and before the call to CreateTriabglePolys, they have their correct values, but directly after, the change back to zero and i cannot for the life of me work out why.

    Thanks for any help.
    Last edited by SLH; Dec 7th, 2003 at 12:13 PM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    just a hunch

    CUSTOMVERTEX Corners[3]; //shouldn't this be 4?
    I don't live here any more.

  3. #3

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Don't think so because arrays start from 0 don't they? So the array has 4 elements numbered 0 up to 3
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  4. #4
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    Don't think so because arrays start from 0 don't they? So the array has 4 elements numbered 0 up to 3
    Close

    Code:
    int myArray[3];
    The number inside the brackets is the number of elements. There are 3 elements, numbered from 0 to 2.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  5. #5

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Ah, thanks for the clarification
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Which explains the changing values: you were overwriting them by changing other variables, because those variables shared the memory with your fictional variables.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    BTW, this is one of the most common VB convert mistakes made.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Originally posted by CornedBee
    BTW, this is one of the most common VB convert mistakes made.
    Ah well, glad to see i'm not the first.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  9. #9
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Frankly, I'm stunned, I actually managed to spot a C++ problem!

    I've arrived.
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width