Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

sudo

Can someone find the bug in this MD2 code?

This topic is 5654 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

I''m trying to write an MD2 loader. For some reason, it won''t read in the triangle data properly. I have successfully read in the file header and the frames, but when I try to load the triangles I always get junk. The code segment under suspicion is as follows triangle_t *tris = new triangle_t[ header.numTriangles ]; inFile.seekg( header.offsetTriangles, ios::beg ); inFile.read( (byte *)tris, sizeof(triangle_t) * header.numTriangles ); header is the file header, inFile is an ifstream, and triangle_t is the triangle type. Every time this code runs, all of the vertex indices get a value of -12851. I have verified the integrity of the MD2 file in question both using other loaders and via a hex editor. I know the 3 lines of code don''t give a huge picture, but I think it''s a simple error and I didn''t want to bog anyone down. If it turns out that there''s nothing wrong with the above, then I guess I start looking again =). sudo

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster

-12851 is 0xcdcd in hex, this is the value for uninitialized data for Visual C++ in debug mode.

your read is most likely failing because:

1. header.offsetTriangles is not valid or

2. the file doesn''t exist or

3. your file open function didn''t get called or

4. header.numTriangles is not valid

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster

-12851 is 0xcdcd in hex, this is the value for uninitialized data for Visual C++ in debug mode.

your read is most likely failing because:

1. header.offsetTriangles is not valid or

2. the file doesn''t exist or

3. your file open function didn''t get called or

4. header.numTriangles is not valid


thanks for your help. I had checked all of these and had almost given up. Turns out I forgot to open the file in binary mode and the first 3 bytes at the position I was reading from were all zero. If I recall correctly, 3 nulls are used to indicate the end of some files. However, I could just be making that up. Oh well.

thanks again,
sudo

Share this post


Link to post
Share on other sites

  • 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!