Hi all,
I'm fairly new to C++, and even newer to Computer Graphics, and I've been assigned a parser/loader for Wavefront OBJ files, but I kept getting an error in the file parser:
'Run-Time Check Failure #2 - Stack around the variable 'c' was corrupted.'
And here's my code:
void loader(char* fileName)
{
ifstream in;
in.open(fileName, ifstream::in);
if(!in)
{
cout << "Error:File Not Open";
exit (1);
}
NormalNum = 0;
TriangleNum = 0;
VertexNum = 0;
GLfloat x, y, z;
GLubyte a, b, c;
char str[512];
while(in)
{
in.getline(str, 512);
if (str[0]=='v' && str[1]=='n')
{
printf("1");
sscanf_s(str,"vn %f %f %f", &x, &y, &z);
printf("1.2");
NormalArray.push_back(x);
NormalArray.push_back(y);
NormalArray.push_back(z);
NormalNum++;
}
else
if (str[0]=='v')
{
sscanf_s(str, "v %f %f %f",&x, &y, &z);
VertexArray.push_back(x);
VertexArray.push_back(y);
VertexArray.push_back(z);
VertexNum++;
}
else
if (str[0]=='f')
{
sscanf_s(str,"f %d %d %d", &a, &b, &c);
IndexArray.push_back(a);
IndexArray.push_back(b);
IndexArray.push_back(c);
TriangleNum++;
}
}
in.close();
}
I've run some flags troughout the code, and I can say the code is stopping after the in.close(), I'm assuming it is getting some error in freeing the memory for the variable.
BTW, I'm using Visual Studio 2010, and I'm a computer sciences student, so I can take some jargon ;)
EDIT: This is coded inside a struct like this:
typedef struct _Model{
int VertexNum, NormalNum, TriangleNum;
vector<GLfloat> VertexArray;
vector<GLfloat> NormalArray;
vector<GLubyte> IndexArray;
void loader(char* fileName)
Thankz