Indexing into an arrays with pointers of arrays
I'm trying to do some semi-complex object initializing for a raytracer in C++.

The following code is for adding triangular faces to an object via an array. **This works:**

    // "newTriangles" is a class; the object itself
    // "faces" is an array of "triangle", a struct with three ints in it
    // "nfaces" is an int of the number of faces which I use to initialize the array:
    newTriangles->faces = new triangle[newTriangles->nFaces];

    for (int i = 0; i < newTriangles->nFaces; ++i)
    {
        // grab values
        newTriangles->faces[i].v1 = a;
        newTriangles->faces[i].v2 = b;
        newTriangles->faces[i].v3 = c;
    }

I can print out the values `newTriangles->faces[i].v1`, `.v2`, and `.v3` here and it works.

`newTriangles` has a method in which I attempt to access `vertices[faces[i].v1].x` (`vertices` is another array inside `newTriangles`). Here's the weird part: It works if the `faces` array is less than 8 elements long. If it's 8 elements or longer, it throws an access violation error when I run my program. If I mouse over the line, it shows `v1` as having an unusual value like 1074790400 when it should be a small integer. So something is going wrong with my pointers; but it's just weird that it happens on an array of 8+ elements but not <=7.

Any thoughts?
Indexing into an arrays with pointers of arrays
===

I'm trying to do some semi-complex object initializing for a raytracer in C++.

The following code is for adding triangular faces to an object via an array. **This works:**

    // "newTriangles" is a class; the object itself
    // "faces" is an array of "triangle", a struct with three ints in it
    // "nfaces" is an int of the number of faces which I use to initialize the array:
    newTriangles->faces = new triangle[newTriangles->nFaces];

    for (int i = 0; i < newTriangles->nFaces; ++i)
    {
        // grab values
        newTriangles->faces[i].v1 = a;
        newTriangles->faces[i].v2 = b;
        newTriangles->faces[i].v3 = c;
    }

I can print out the values `newTriangles->faces[i].v1`, `.v2`, and `.v3` here and it works.

`newTriangles` has a method in which I attempt to access `vertices[faces[i].v1].x` (`vertices` is another array inside `newTriangles`). Here's the weird part: It works if the `faces` array is less than 8 elements long. If it's 8 elements or longer, it throws an access violation error when I run my program. If I mouse over the line, it shows `v1` as having an unusual value like 1074790400 when it should be a small integer. So something is going wrong with my pointers; but it's just weird that it happens on an array of 8+ elements but not <=7.

Any thoughts?