I am sorry
Here is the whole function:
char Model::LoadModel(char *filename){ int i; FILE *file; unsigned short chunk_id; unsigned int chunk_length; unsigned char char; unsigned short howmany = 0; unsigned short flags = 0; if (fopen_s(&file,filename, "rb")) return 0; while (ftell(file) < _filelength (_fileno (file))) { fread (&chunk_id, 2, 1, file); fread (&chunk_length, 4, 1, file); switch (chunk_id) { case 0x4d4d: break; case 0x3d3d: break; case 0x4000: i=0; do { fread (&char, 1, 1, file); this->name=char; i++; }while(char != '\0' && i<20); break; case 0x4100: break; case 0x4110: fread (&howmany, sizeof (unsigned short), 1, file); this->vertices_qty = howmany; vertex = new vertex_class[vertices_qty]; { fread (&vertex.x, sizeof(float), 1, file); fread (&vertex.y, sizeof(float), 1, file); fread (&vertex.z, sizeof(float), 1, file); } break; case 0x4120: fread (&howmany, sizeof (unsigned short), 1, file); this->polygons_qty = howmany; polygons = new polygon_class[howmany]; for (i=0; i<howmany; i++) { fread (&polygons.a, 2, 1, file); fread (&polygons.b, 2, 1, file); fread (&polygons.c, 2, 1, file); fread (&flags, 2, 1, file); } break; case 0x4140: fread (&howmany, sizeof (unsigned short), 1, file); mapcoord = new mapcoord_class[howmany]; for (i=0; i<howmany; i++) { fread (&mapcoord.u, sizeof (float), 1, file); fread (&mapcoord.v, sizeof (float), 1, file); } break; } } fclose (file); return (1); }
It's a .3ds loader
It loads normally the vertexes but when it comes to polygons at run time it throws:
Unhandled exception at 0x00462840 in main.exe: 0xC0000005: Access violation reading location 0x00000004.
I cant find why and I dont understand why provided that it reads normally the vertexes,
it stalls when reading the polygons
The model class has private pointers:
vertex_class* vertex;
polygon_class* polygon;
mapcoord_class* mapcoord;
where:
class vertex_class{public: float x,y,z;};class polygon_class{public: unsigned int a,b,c;};class mapcoord_class{public: float u, v;};
thanks
[Edited by - Lord_Vader on September 9, 2006 2:43:53 PM]