Sign in to follow this  
fpsgamer

My Model Loader: Checking for errors...

Recommended Posts

(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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this