求助: 0x0023320f 处有未经处理的异常: 0xC0000005: 写入位置 0x00000000 时发生访问冲突

富人 2016-10-30 12:22:27
我在写计算机图形学的Meshviewer程序,程序可运行,但是在载入.m文件时就崩溃了。
错误提示:MyMeshviewer.exe 中的 0x0023320f 处有未经处理的异常: 0xC0000005: 写入位置 0x00000000 时发生访问冲突
昨天弄了一整天也没弄出来,求帮助,先谢谢大家了!

以下是读取文件import的函数:
void import(char *filename,HE_vert* vertex[],tmpface f[], int* vertex_num, int* face_num)
{
FILE *file;
char first; //首字母
int index_vertex,index_face,v1,v2,v3;
float x,y,z;
//open file
file=fopen(filename,"r"); //

while((first=fgetc(file))!= EOF) //
{
switch (first)
{
case 'V': if ( fscanf(file,"ertex %d %f %f %f \n",
&index_vertex,&x,&y,&z) == 4 )
{
//保存点的信息
vertex[index_vertex-1]->x = (GLfloat)x; //运行到这一行就崩溃了。 只能单步调试到这
vertex[index_vertex-1]->y = (GLfloat)y;
vertex[index_vertex-1]->z = (GLfloat)z;
vertex[index_vertex-1]->edge = NULL;
vertex[index_vertex-1]->n[0] = 0;
vertex[index_vertex-1]->n[1] = 0;
vertex[index_vertex-1]->n[2] = 0;

}
break;
case 'F': if ( fscanf(file,"ace %d %d %d %d\n",&index_face,&v1,&v2,&v3) == 4)
{
//保存面的信息
f[index_face-1].v[0]=v1;
f[index_face-1].v[1]=v2;
f[index_face-1].v[2]=v3;
}
break;
case '#': do
{ first =fgetc(file);
}while( first != '\n' && first != EOF);
break;
}
}

.m文件类似于: (只各截取了一部分)
# Created on 2012/09/12 05:06:44 using:
# filtermesh gargoyle.m -removeinfo
# (Timing on cpu=x86 Family 6 Model 37 Stepping 2, GenuineIntel host=?)
# (_readmesh: 0.18)
# (Filtermesh: 0.20)
Vertex 1 4708.86 164.285 5159.54
Vertex 2 4198.64 8094.81 3301.98
Vertex 3 5762 53.5208 4312.48
Vertex 4 5154.16 3022.08 626.582
Vertex 5 2477.44 2666.24 2925.96
Vertex 6 3169.58 3189.75 3081.76
Vertex 7 3289.53 6143.84 1667.56
Vertex 8 5350.23 5478.56 1671.47
Vertex 9 7871.43 9864.69 842.776
Vertex 10 3455.54 8370.09 4684.36
Face 1 10029 8167 3625
Face 2 9940 11231 14635
Face 3 11558 19219 10029
Face 4 12514 10574 1646
Face 5 863 6811 9058
Face 6 6468 8009 9490
Face 7 9599 16187 17113
Face 8 18959 15159 14537
Face 9 10970 13912 15342
...全文
347 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-10-31
  • 打赏
  • 举报
回复
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack即“调用堆栈”里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处,看不懂时双击下一行,直到能看懂为止
小灸舞 2016-10-31
  • 打赏
  • 举报
回复
估计是你的vertex[index_vertex-1]是NULL指针
自己打印下或者单步一下就知道了。
单步调试和设断点调试(VS IDE中编译连接通过以后,按F10或F11键单步执行,按Shift+F11退出当前函数;在某行按F9设断点后按F5执行停在该断点处。)是程序员必须掌握的技能之一。
富人 2016-10-30
  • 打赏
  • 举报
回复
以下是结构体的定义: struct HE_edge { HE_vert* vert; // vertex at the end of the half-edge HE_edge* pair; // oppositely oriented adjacent half-edge HE_face* face; // face the half-edge borders HE_edge* prev; HE_edge* next; // next half-edge around the face }; struct HE_vert { float x; float y; float z; float n[3]; HE_edge* edge; // one of the half-edges emantating from the vertex }; struct HE_face { HE_edge* edge; // one of the half-edges bordering the face }; typedef struct tmpface { int v[3]; } ; tmpface f[90000]; HE_vert* vertex[90000]; HE_face* faces[90000]; HE_edge* edges[300000];
富人 2016-10-30
  • 打赏
  • 举报
回复
引用 2 楼 hijack00 的回复:
你把读取到的值打印出来看看,如index_vertex,x,y等等。 你的程序崩溃很有可能是数组越界了。你重点看看index_vertex的值(是不是负数或者0)?还有就是看看你的那个数组vertex[]有多大
好的,我去试试!谢谢!
hijack00 2016-10-30
  • 打赏
  • 举报
回复
你把读取到的值打印出来看看,如index_vertex,x,y等等。 你的程序崩溃很有可能是数组越界了。你重点看看index_vertex的值(是不是负数或者0)?还有就是看看你的那个数组vertex[]有多大

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧