but that code is not the problem i guess, this is the code which states the errormessage:
Code: Select all
int SingleRace::ParseSingleRace(const char* race) {
FILE *f;
char ReadBuffer[256];
char sBuffer[256];
getcwd(ReadBuffer,100);
sprintf(sBuffer, "%s/Races/%s",ReadBuffer, race);
//DebugTools::PrintTextLoop(sBuffer);
//DebugTools::PrintTextLoop("Het komt nog tot hiero \n");
if((f = fopen(sBuffer,"rb")) != NULL) {
// parse the info.
// read version
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+8),"%d",&version);
// read difficulty
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+11),"%d",&difficulty);
// read difficulty
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+11),"%d",&maxplayers);
// start reading x and y start(finish).
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+8),"%d",&startPos.y );
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+8),"%d",&startPos.x );
// start reading x and y halfway.
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+9),"%d",&halfwayPos.y );
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+9),"%d",&halfwayPos.x );
// read the dimensions
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+2),"%d",&dimension.x );
fgets(ReadBuffer, 256, f);
sscanf((ReadBuffer+2),"%d",&dimension.y );
// create the 2D array
Track = new std::vector<std::vector<TrackPart*>*>;
//DebugTools::PrintTextLoop("Het komt nog tot hiero \n");
for(int i=0;i<dimension.y;i++){
fgets(ReadBuffer, 256, f);
// readbuffer has now one row of the field.
//create the vector for 2d array
TrackLine = new std::vector<TrackPart*>;
for(unsigned int j=0;j<strlen(ReadBuffer);j++){
DebugTools::PrintText(&ReadBuffer[j]);
switch(ReadBuffer[j]){
case '1':
//straight1.addLocation(i*BLOCKSIZE, 0.0f, j*BLOCKSIZE, i, j);
tmpPart = new TrackPart(1);
tmpPart->setPosition(j*BLOCKSIZE, 0.0f, i*BLOCKSIZE);
tmpPart->setObject(&trackpartStraight2);
tmpPart->setWaypoints(1);
TrackLine->push_back(tmpPart);
break;
case '2':
//straight2.addLocation(i*BLOCKSIZE, 0.0f, j*BLOCKSIZE, i, j);
tmpPart = new TrackPart(2);
tmpPart->setPosition(j*BLOCKSIZE, 0.0f, i*BLOCKSIZE);
tmpPart->setObject(&trackpartStraight1);
tmpPart->setWaypoints(2);
TrackLine->push_back(tmpPart);
break;
case '3':
//corner1.addLocation(i*BLOCKSIZE, 0.0f, j*BLOCKSIZE, i, j);
tmpPart = new TrackPart(3);
tmpPart->setPosition(j*BLOCKSIZE, 0.0f, i*BLOCKSIZE);
tmpPart->setObject(&trackpartCorner4);
tmpPart->setWaypoints(3);
TrackLine->push_back(tmpPart);
break;
case '4':
//corner2.addLocation(i*BLOCKSIZE, 0.0f, j*BLOCKSIZE, i, j);
tmpPart = new TrackPart(4);
tmpPart->setPosition(j*BLOCKSIZE, 0.0f, i*BLOCKSIZE);
tmpPart->setObject(&trackpartCorner1);
tmpPart->setWaypoints(4);
TrackLine->push_back(tmpPart);
break;
case '5':
//corner3.addLocation(i*BLOCKSIZE, 0.0f, j*BLOCKSIZE, i, j);
tmpPart = new TrackPart(5);
tmpPart->setPosition(j*BLOCKSIZE, 0.0f, i*BLOCKSIZE);
tmpPart->setObject(&trackpartCorner2);
tmpPart->setWaypoints(5);
TrackLine->push_back(tmpPart);
break;
case '6':
//corner4.addLocation(i*BLOCKSIZE, 0.0f, j*BLOCKSIZE, i, j);
tmpPart = new TrackPart(6);
tmpPart->setPosition(j*BLOCKSIZE, 0.0f, i*BLOCKSIZE);
tmpPart->setObject(&trackpartCorner3);
tmpPart->setWaypoints(6);
TrackLine->push_back(tmpPart);
break;
case ' ':
TrackLine->push_back(NULL);
break;
}
}
//save the array in the 2d array
Track->push_back(TrackLine);
}
// done so close
fclose(f);
}
else {
DebugTools::PrintTextLoop("Error reading the race \n");
}
return 0;
}