Skip to main content
gamedev.net
🔒 Locked

loading problem

Started by hello_there 5 replies 350+ views
Original Post
hello_there
hello_there
I''m trying to load a name of a file from another file but it''s not loading properly. i''ve been looking over it for a while and i can''t see the problem so could someone else please have a quick look over this code and tell me the problem. the proplem is with TileSetLocation which is a char * TileSetLocation; and it is set to NULL in the constructor. also the writing to the file first is only temporary till i get my level editor working. bool CTerrain::Load(char *FileName) { FILE *Load; dint Temp=150; dint Temp2=150; double Moose=0; dint size=8; Load = fopen(FileName,"wb"); fwrite(&size,sizeof(dint),1,Load); fwrite("Temp.set",sizeof(char),size,Load); fwrite(&Temp,sizeof(dint),1,Load); fwrite(&Temp2,sizeof(dint),1,Load); for(dint indx=0;indx<(Temp*Temp2);indx++) { Moose = FRAND*(FRAND); fwrite(&Moose,sizeof(double),1,Load); if(Moose < 0)Moose = 0.3;else Moose = 1; fwrite(&Moose,sizeof(double),1,Load); fwrite(&Moose,sizeof(double),1,Load); fwrite(&Moose,sizeof(double),1,Load); } fclose(Load); FILE *LoadTerrain; double TempX=0; double TempZ=0; dint Counter=0; dint LengthOfName; LoadTerrain = fopen(FileName,"rb"); if(LoadTerrain == NULL) throw "ERROR: Failed To Load Map File"; // Load in the length of the TileSet Location fread(&LengthOfName,sizeof(dint),1,LoadTerrain); // Set aside memory for TileSetLocation TileSetLocation = new char[LengthOfName+1]; // Load in the location fread(&TileSetLocation,sizeof(char),LengthOfName,LoadTerrain); // Load in the map dimensions fread(&NoVertexX,sizeof(dint),1,LoadTerrain); fread(&NoVertexZ,sizeof(dint),1,LoadTerrain); // Make sure something supid wasn''t loaded if((NoVertexX < 50 || NoVertexZ < 50)|| (NoVertexX > 150 || NoVertexZ > 150)) throw "ERROR: Invalid Map Size"; if(VertexData != NULL || ColourData != NULL) throw "ERROR: Level Data Not Ready For Loading Call UnLoad() First"; VertexData = new double[NoVertexX*NoVertexZ][3]; ColourData = new double[NoVertexX*NoVertexZ][3]; for(dint indx=0;indx<(NoVertexX*NoVertexZ);indx++) { // Load in the height at each vertex. // X and Z points are always the same so they are generated not loaded fread(&VertexData[indx][1],sizeof(double),1,LoadTerrain);// Height(Y axis) fread(&ColourData[indx][0],sizeof(double),1,LoadTerrain);// R fread(&ColourData[indx][1],sizeof(double),1,LoadTerrain);// G fread(&ColourData[indx][2],sizeof(double),1,LoadTerrain);// B } fclose(LoadTerrain); ofstream File("HI.txt"); File <
____________How could hell be worse?
hello_there
hello_there
opps sorry about double posting it came up with a thing said it didn''t work or something.
____________How could hell be worse?
felisandria
felisandria
You can delete your double posts by editing them, there will be a check box in the top to allow you to delete.

What''s the error you''re getting, exactly?

-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
hello_there
hello_there
the other post was already deleted anyway.

the error in my game or what it said when i posted?

[edited by - hello_there on February 1, 2004 11:07:53 PM]
____________How could hell be worse?
hello_there
hello_there
oh you have to do it like this
char *name = "Temp.set";
fwrite(&name,sizeof(char),size,Load);
____________How could hell be worse?
SnakeHunta
SnakeHunta
i think maybe "Temp.set" is 9 in size not 8 since there is a null terminator at the end

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.