Advertisement

See Anything I missed(source)

Started by July 01, 2000 09:26 PM
10 comments, last by Esap1 24 years, 5 months ago
PLEASE SCROLL TO BOTTOM! I was hoping it wouldnt come to this but I just cant figure out the problem. This function loads an ASE file. But it crashes when I have more Texture Coordinates than number of Vertices. Heres the classes. (Sorry for the length). class Map_class { public: Object_class *Object; long numObjects; int LoadASE(char *file); int DrawMap(); }; class Object_class { public: //unsigned int VertexIndex[MAX_INDEX]; Vertex_class *Vertex; Face_class *Face; unsigned int numVertex; unsigned int numFace; unsigned int Texture; float *tu; //Pointer to the list of TU's float *tv; //Pointer to the list of TV's int active; int Draw(); Object_class(){active=1;} inline Object_class &operator = (Object_class &O); }; struct Face_class { unsigned int Index[3]; unsigned long TexIndex[3]; //Texture Coord Index Vertex_class Normal; inline Face_class &operator = (Face_class &F); Face_class(){Index[0]=Index[1]=Index[2]=0;} }; struct Vertex_class { float x,y,z; inline Vertex_class &operator = (Vertex_class &V); }; ------------------------------------------------------ And heres the function. int Map_class::LoadASE(char *filename) { int done=0; char temp[32]; char temp2[32]; unsigned long index1,index2,index3; unsigned long Mesh_NumVertex=0; unsigned long Mesh_NumFaces=0; unsigned long Mesh_NumTVertex=0; unsigned long Mesh_NumTVFaces=0; unsigned long currObject=0; unsigned long numObject=1; unsigned long currTVertex=0; unsigned long currFace=0; unsigned long currTVFace=0; float ftemp; Object_class TempObject; FILE *fp; fp = fopen(filename,"r"); if(fp<=0){return -1;} //Find Out How many Objects there are in the file while(fscanf(fp,"%s",&temp)!=EOF) { if(strcmp(temp,"*MESH_NUMVERTEX")==0) { numObject+=1; } } fseek(fp,0,SEEK_SET); Console.Print("Loading ASE "); Console.Print(filename); //Alocate enough space for the objects Object = new Object_class[numObject]; while(done!=1) { //Find MESH_NUMVERTEX while(strcmp(temp,"*MESH_NUMVERTEX")!=0)if(fscanf(fp,"%s",&temp)==EOF){goto DONE1;} if(fscanf(fp,"%d",&Mesh_NumVertex)==EOF)goto END1; Object[currObject].Vertex = new Vertex_class[Mesh_NumVertex]; //Get MESH_NUMFACES while(strcmp(temp,"*MESH_NUMFACES")!=0)if(fscanf(fp,"%s",&temp)==EOF)goto END1; if(fscanf(fp,"%d",&Mesh_NumFaces)==EOF)goto END1; Object[currObject].Face = new Face_class[Mesh_NumFaces]; //Find MESH_VERTEX while(strcmp(temp,"*MESH_VERTEX")!=0)if(fscanf(fp,"%s",&temp)==EOF)goto END1; //Get First Vertex if(fscanf(fp,"%d",&index1)==EOF)goto END1; //fscanf(fp, "%f %f %f",&Object[currObject].Vertex[0].x, &Object[currObject].Vertex[0].z, &Object[currObject].Vertex[0].y); if(fscanf(fp,"%f",&Object[currObject].Vertex[0].x)==EOF)goto END1; if(fscanf(fp,"%f",&Object[currObject].Vertex[0].z)==EOF)goto END1; if(fscanf(fp,"%f",&Object[currObject].Vertex[0].y)==EOF)goto END1; for(unsigned int currVertex=1; currVertex<Mesh_NumVertex; currVertex++) { //fscanf(fp, "*MESH_VERTEX %d %f %f %f",&index1, &Object[currObject].Vertex[currVertex].x, &Object[currObject].Vertex[currVertex].z, &Object[currObject].Vertex[currVertex].y); while(strcmp(temp2,"*MESH_VERTEX")!=0)if(fscanf(fp,"%s",&temp2)==EOF)goto END1; if(fscanf(fp,"%d",&temp2[0])==EOF)goto END1; if(fscanf(fp,"%f",&Object[currObject].Vertex[currVertex].x)==EOF)goto END1; if(fscanf(fp,"%f",&Object[currObject].Vertex[currVertex].z)==EOF)goto END1; if(fscanf(fp,"%f",&Object[currObject].Vertex[currVertex].y)==EOF)goto END1; } //FIND MESH_FACE while(strcmp(temp,"*MESH_FACE")!=0)if(fscanf(fp,"%s",&temp)==EOF)goto END1; //fscanf(fp, "0: A: %d B: %d C: %d AB: %d BC: %d CA: %d",&Object[currObject].Face[0].Index[0],&Object[currObject].Face[0].Index[1],&Object[currObject].Face[0].Index[2], &index1,&index2,&index3); if(fscanf(fp, "%s",temp)==EOF)goto END1; //0: if(fscanf(fp, "%s",temp)==EOF)goto END1; //A: if(fscanf(fp, "%d",&Object[currObject].Face[0].Index[0])==EOF)goto END1; if(fscanf(fp, "%s",temp)==EOF)goto END1; //B: if(fscanf(fp, "%d",&Object[currObject].Face[0].Index[1])==EOF)goto END1; if(fscanf(fp, "%s",temp)==EOF)goto END1; //C: if(fscanf(fp, "%d",&Object[currObject].Face[0].Index[2])==EOF)goto END1; for(currFace=1; currFace<Mesh_NumFaces; currFace++) { //fscanf(fp, "*MESH_FACE 0: A: %d B: %d C: %d AB: %d BC: %d CA: %d",&Object[currObject].Face[currFace].Index[0],&Object[currObject].Face[currFace].Index[1],&Object[currObject].Face[currFace].Index[2], &index1,&index2,&index3); //fscanf(fp, "%s",temp); //*MESH_FACE while(strcmp(temp,"*MESH_FACE")!=0)if(fscanf(fp,"%s",&temp)==EOF)goto END1; if(fscanf(fp, "%s",temp)==EOF)goto END1; //0: if(fscanf(fp, "%s",temp)==EOF)goto END1; //A: if(fscanf(fp, "%d",&Object[currObject].Face[currFace].Index[0])==EOF)goto END1; if(fscanf(fp, "%s",temp)==EOF)goto END1; //B: if(fscanf(fp, "%d",&Object[currObject].Face[currFace].Index[1])==EOF)goto END1; if(fscanf(fp, "%s",temp)==EOF)goto END1; //C: if(fscanf(fp, "%d",&Object[currObject].Face[currFace].Index[2])==EOF)goto END1; } //Texture VERTEX while(strcmp(temp,"*MESH_NUMTVERTEX")!=0)if(fscanf(fp,"%s",&temp)==EOF)goto END1; if(fscanf(fp,"%d",&Mesh_NumTVertex)==EOF)goto END1; Object[currObject].tu = new float[Mesh_NumTVertex]; Object[currObject].tv = new float[Mesh_NumTVertex]; for(currTVertex=0; currTVertex<Mesh_NumTVertex; currTVertex++) { while(strcmp(temp,"*MESH_TVERT")!=0)if(fscanf(fp,"%s",&temp)==EOF)goto END1; if(fscanf(fp,"%d",&temp[0])==EOF)goto END1; if(fscanf(fp,"%f",&Object[currObject].tu[currTVertex])==EOF)goto END1; //Texture X if(fscanf(fp,"%f",&Object[currObject].tv[currTVertex])==EOF)goto END1; //Texture Y if(fscanf(fp,"%f",&ftemp)==EOF)goto END1; //Texture Z? } //Texture Face Index while(strcmp(temp,"*MESH_NUMTVFACES")!=0)if(fscanf(fp,"%s",&temp)==EOF)goto END1; if(fscanf(fp,"%d",&Mesh_NumTVFaces)==EOF)goto END1; //Number of Texture Faces and Faces must be the same if(Mesh_NumTVFaces!=Mesh_NumFaces)goto END1; for(currTVFace=0; currTVFace<Mesh_NumFaces; currTVFace++) { while(strcmp(temp,"*MESH_TFACE")!=0)if(fscanf(fp,"%s",&temp)==EOF)goto END1; if(fscanf(fp,"%d",&temp[0])==EOF)goto END1; if(fscanf(fp,"%d",&Object[currObject].Face[currTVFace].TexIndex[0])==EOF)goto END1; if(fscanf(fp,"%d",&Object[currObject].Face[currTVFace].TexIndex[1])==EOF)goto END1; if(fscanf(fp,"%d",&Object[currObject].Face[currTVFace].TexIndex[2])==EOF)goto END1; } //FIND MESH_FACENORMAL for(unsigned int currNormal=0; currNormal<Mesh_NumFaces; currNormal++) { while(strcmp(temp,"*MESH_FACENORMAL")!=0)if(fscanf(fp,"%s",&temp)==EOF)goto END1; //fscanf(fp, "%d %f %f %f", &index1, &Object[currObject].Face[currNormal].Normal.x, &Object[currObject].Face[currNormal].Normal.z, &Object[currObject].Face[currNormal].Normal.y); if(fscanf(fp,"%d",&temp[0])==EOF)goto END1; if(fscanf(fp,"%f",&Object[currObject].Face[currNormal].Normal.x)==EOF)goto END1; if(fscanf(fp,"%f",&Object[currObject].Face[currNormal].Normal.z)==EOF)goto END1; if(fscanf(fp,"%f",&Object[currObject].Face[currNormal].Normal.y)==EOF)goto END1; //Object[currObject].Face[currNormal].Normal.x = (float)index1; } //FIND WHICH MATERIAL while(strcmp(temp,"*MATERIAL_REF")!=0)if(fscanf(fp,"%s",&temp)==EOF)goto END1; if(fscanf(fp,"%d",&Object[currObject].Texture)==EOF)goto END1; Object[currObject].numFace = Mesh_NumFaces; Object[currObject].numVertex = Mesh_NumVertex; currObject+=1; } DONE1: fclose(fp); numObjects = currObject; Console.Print(" Done!\n"); return currObject; END1: fclose(fp); numObjects = 1; return -1; } Edited by - Esap1 on 7/2/00 1:27:22 PM
Is this post too long?, If you dont see any problems then just post back, "I dont see any problems", so I can look other places,please. thanks in advance.
Advertisement
Cool...an ASE loader. (nes8bit steals source and tries to compile...)CRAP! It''s C++! You win Esap1.

------------------------
Captured Reality
Your code is hilarious.
You display some budding STL skill and are using fscanf''s

You could save yourself some headache by saving the number of objects in the file as the first value (update it if add more dynamically)

WHAT THE HELL ARE YOU USING GOTO''S FOR!
&ltBreaks out a dead fish>
&lgtWhack, whack, whack, whack.... whack>

its hard to tell, I see some syntactical errors but it probably because you didn''t stick a "
    " and "[/source]" around your code.btw, here''s some more C++ hints;  you could use fstream (kinda like oistream technology used in cin & cout & cerr, except for files!) (#include "fstream.h" and you can use all these niffty features <img src="wink.gif" width=15 height=15 align=middle>)  And get rid of those goto''s![source]#include <iostream.h> // fstream will include it if you don''t...#include <fstream.h>main(){fstream fout;cout<<"Hello World!";  //cout outputs to the standard out... its declared in iostreamfout.open("C:\\crap.txt", ios::out);fout<<"Hello harddrive!";}    
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Ewwww GOTO
Advertisement
First what do you mean by Im displaying some budding STL skills. Also, I used fscanf cause I like C, yes, I know how to use file streams. But what was the syntatical errors? Also, Saving the number of Objects in the file as the first value?, I didnt create the ASE Format(I dont think I understand what you mean.) thanks for posting though
I have now found out when I load a file with more Texture Coordinates than there are vertices, the function crashes right at the first part where it finds out how many Objects there are. And if I comment that out, it crashes at the point:
Object = new Object_class[numObject];
WHY!!!!!!!!!!!!!!!!!!!
I change it to
Object = new Object_class[1];
AND IT STILL GIVES ME AN ACCESS VIOLATION, in the debug window at the bottom of the screen in VC6++ it shows a couple hundred:

First-chance exception in Goliath1.exe: 0xC0000005: Access Violation.

Then at the bottom of them it says:

The thread 0xFFFCFFAF has exited with code -1 (0xFFFFFFFF).
The program ''C:\GameDev\Projects\Goliath1\Debug\Goliath1.exe'' has exited with code -1 (0xFFFFFFFF).

Yet when I try to load a Sphere with one texture on it, it works fine, WHAT THE HELL IS HAPPENING, PLEASE SOMEONE HELP ME, IM GOING CRAZY, ITS 2:45AM And Im not going asleep until I FIGURE THIS OUT, PLEASE
EVERY JUST POST AND GIVE ANY IDEA YOU HAVE, NO MATTER HOW STUPID IT IS(OR HOW DUMB YOU ARE) IT DOESNT MATTER, JUST HELP, PLEASE!
Damn I fell asleep, is it that nobody scrolls down this far to read my message?
I''ve never ever seen code with STL fscanf & goto''s.
Until now
I kinda ass-umed you were new to STL ''cause of the fscanf''s & gotos...

Ha its right there, LoadASE... missed it
Did you cut & paste that code with all the fscanf''s & goto''s?

Anyway, but a breakpoint in your Object_class constructor looks like the problems there... accidentally made an array with the wrong value maybe?

- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement