c++ OBJ解析器-第一次机会异常
C++ OBJ Parser - First Chance Exception
我正在尝试创建一个c++程序,该程序将解析。obj文件并在OpenGL中呈现。obj文件中定义的模型。到目前为止,所有这些代码应该做的就是打开一个.obj文件,并将每个顶点放入一个向量中(.obj文件中的顶点定义在以"v"开头的行中)。
我的完整代码是:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
struct vec3{
float x;
float y;
float z;
};
void loadOBJ(const char * Path){
vector<vec3> Vertices;
FILE * OBJFile;
vec3 temp = vec3();
fopen_s(&OBJFile, Path, "r");
char lineHeader[128];
//set to true when there are no more lines in the OBJ file
bool ended = false;
while(!ended){
fscanf_s(OBJFile, "%s", lineHeader);
if(strcmp(lineHeader,"v") == 0){
fscanf_s(OBJFile, "%f %f %fn", &temp.x, &temp.y, &temp.z);
printf("Point: %f %f %fn", temp.x, temp.y, temp.z);
Vertices.push_back(temp);
}else if(lineHeader != NULL){
fscanf_s(OBJFile, "n");
}
else{
ended = true;
}
}
}
int main(){
loadOBJ("example.obj");
cin.get();
return 0;
}
这一行出现问题 fscanf_s(OBJFile, "%s", lineHeader);
如果我注释掉这行,我将不会得到第一次异常。如果我使用字符而不是字符串,我也不会得到第一次机会异常。
我强烈建议使用free,永远不要使用fsanf及其变体。
相关文章:
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 我必须构建我的项目 2 次,第一次失败,因为它无法打开库
- 是什么导致我的循环在第一次迭代中运行得更慢
- QLibrary 函数在第一次调用时工作缓慢
- 第一次尝试使用new动态创建结构数组,程序挂起没有错误
- 为什么第一次迭代后的指针指向随机值?
- 如何防止GUI挂起,同时允许第二次操作与Qt中的第一次操作一起执行
- LAPACK函数在第一次迭代后变慢
- 在Visual studio中调试javaScript.第一次机会例外
- 创建CFrameWnd会给出第一次机会的异常——为什么
- MSXML6 中的第一次机会异常
- 万神殿的第一次机会例外
- 错误地使用fprintf?获取异常 第一次机会异常
- 我的代码中的第一次机会异常
- 暂时禁用第一次机会例外
- Qt读取访问在以下位置发生冲突:0x0,标志=0x0(第一次机会)
- 为什么我得到第一次机会异常,如果没有人调用该函数
- 在0x5919c8ec (msvcr100d.dll)的第一次机会异常:0xC0000005:访问违反读取位置0xfee
- c++ OBJ解析器-第一次机会异常
- 此异常是什么意思>第一次机会异常在 Project3 中0x000007FEFD38A06D时未处理的异常.exe