求助: 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