Original Post
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 <