Jump to content
  • Advertisement
Sign in to follow this  

My Model Loader: Checking for errors...

This topic is 4351 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!