我正在为 .obj 文件编写解析器,并且在此代码块的 for 循环中某处引发了未处理的异常,我无法找到它。Visual Studio 错误消息说它位于 ntdll.dll 中。然后代码在 ostream 文件中中断。当我使用断点时,程序在多次迭代之前不会崩溃。
//Intitialising index array for that part and returning to the start of the
vertex defining period
//iCount is the number of indices that are being read in
//Position is the saved position within the .txt file that has been reached
data[k].indices = new triangle[iCount];
data[k].noIndices = iCount;
data[k].verTex = new point3D[iCount];
int a,b,c,d,e,f;
int check = 0;
inFile.seekg(position - 1);
cout << "Icount" << iCount << endl;
//Getting index data
for(int j = 0; j < iCount; j++)
{
char buff[40];
inFile.getline(buff, 40);
int matched = sscanf(buff, "f %d/%d %d/%d %d/%d", &a, &b, &c, &d, &e, &f);
//Zero align the indices and store the data
data[k].verTex[j].x = b - 1;
data[k].verTex[j].y = d - 1;
data[k].verTex[j].z = f - 1;
//Zero align the indices and store the data
data[k].indices[j].a = a - 1;
data[k].indices[j].b = c - 1;
data[k].indices[j].c = e - 1;
}
编辑:添加此代码块后,将失败写入控制台,直到堆损坏。这是因为 sscanf() 如果在没有断点的情况下运行,则在第一次迭代后返回 -1
if(matched != 6)
{
cout << "fail";
}