Original Post
I doubt this is the proper methodology for doing it, so if someone could point a better way to do this, I''d much appreciate it.
I have a text file containing geometry data in this form:
2 -2.00 2.00 -5.00 2 0.00 0.00 -2.00 0.00 -5.00 2 0.00 1.00 2.00 0.00 -5.00 2 1.00 1.00 2.00 2.00 -5.00 2 1.00 1.00 2.00 0.00 -5.00 2 1.00 0.00 -2.00 2.00 -5.00 2 0.00 1.00The first line indicates an integer declaring the number of triangles within the file. During file-loading, I use the following bit to read that first line in:
fscanf(Worldat, "%d", &numtri); numvert = (numtri * 3)+1;In this way, I turn numtri, number of triangles, into the number of vertices, numvert. Now, I have a structure called Vector declared in a header file:
typedef struct{
float x;
float y;
float z;
} Vector;
extern Vector* Geometry;
Back in the file-loading code, I try to declare a dynamic array of this structure to hold the information in the file:
Vector *Geometry;
Geometry = new Vector[numvert];
for (int i=0; i<numvert; i++) {
fscanf(Worldat, "%f %f %f %d %f %f", &Geometry[i].x, &Geometry[i].y, &Geometry[i].z);
}
Everything compiles beautifully. However, at run-time, I get one of those nice "EngineTest has caused an error EngineTest.exe" boxes. On Debug, tells me there''s an "Unhandled Exception in EngineTest.exe: 0X0000005: Access Violation" which then takes me to a place in something called fassign in what I can only assume is a .c file belonging to the compiler.
Why is it doing this? I''ve never done anything like this before, and everytime I''ve come across an unhandled exception like this, it''s been a really simple mistake on my part. I''d love to learn from it, but everything I''ve read tells me I''m doing this right.
Much thanks and appreciation in advance to whomever can help me out!