My Model Loader: Checking for errors...

Started by
-1 comments, last by fpsgamer 17 years, 8 months ago
(1) My model loader looks something like this

ifstream inFile(fileName, ios::binary);

inFile.seekg(0, ios::end);
int fileLength = inFile.tellg();
inFile.seekg(0, ios::beg)l

//prepare to parse
while(inFile.good())
{
//parse
inFile.read(blah blah...);
}
//done parsing

int finalPos = inFile.tellg();

if(fileLength != endPos) //error







I thought I could check the file length before the main loop, then at the end check the position of the get pointer to see if they matched. If they didnt match then I could say that we exited the loop prematurely (due to some io error) but that doesnt seem to work. The last call of tellg() seems to always return -1. (2) Also what happens if the model format isnt formatted properly (or isnt the right format at all and one of the reads inside the loop attempts to read some memory it doesnt have access to? All reads inside the loop are unchcked since there is an assumption the data will adhere to the format. How can I avoid a crash in that situation? Also since I skip certain portions of the file format by use of a default case inside a switch statement, it means any file can "pass" the parse but would most likely result in reading past the end of the file in memory resulting in a crash. I always get so absorbed in trying to handle a million and one potential errors, what is the "right" thing to do in this case? edit: The model format is 3Ds. It doesn't seem to have a header so it doesn't look like i can perform any trivial rejections of non 3DS files.

This topic is closed to new replies.

Advertisement