Daily Archive for December 3rd, 2009

OpenGBH progress

As you can see, I now switched to the utility part of the engine. I’m working on improving all the low-level stuff in the engine, and gears that make it go. Today I found and fixed some really bad bugs, and I started adding error handling to everywhere where it makes sense – in a hope that even if error occurs, it can go through it, or at least around it.

This is C, we got no exceptions here, so no real exception handling! Anyway, there was this one bug in chunk loader (as I thought) – for some reason, when I added error reporting for reading beyond chunk limits, it said that I was exceeding it almost everywhere. Usually just by a few bytes – 1 to 5 bytes more than chunk size is. And also seemingly because of that it started reading garbage data instead of chunks, later leading to skipping half of maps.

Anyway, I traced this problem not to the loader, but to OpenGTA2 tools themselves – they didn’t write proper chunk size, because I forgot how fwritef works. I used this code: chunksize += fwrite(&numchars,2,1,out);, while fwrite actually returns count of items written, not amount of bytes written. My bad, I fixed it, and it works now: chunksize += 2*fwrite(&numchars,2,1,out);