Saturday, June 20, 2015

Gash - Does No Harm

I continued investigating NextGenGraphics's reimport corruption problem demonstrated yesterday. The first thing I noticed was that I had completely forgotten to check if the chunk had a constant decompressed size; ToFiles always wrote the UInteger representing the decompressed length. That was certainly the cause of the image distortion, but attempting to launch Keen with EGA resources from the fixed version resulted in an MM_GetPtr: Out of memory! error immediately after the "loading" B800 screen. I was fairly confused about that too, especially because Abiathar could use those EGA resources just fine - there were no extra lines or other distortions.

A little looking around in the FromFiles method revealed a precarious situation: the MemoryStream stored in RawCompChunks included the 4-byte decompressed length. It wasn't the source of any corruption because the stream's position was moved to the start of the real data, but I'm sure the arrangement would have resulted in baffling bugs down the road.

It was after fixing the FromFiles chunkifier that I realized there must be a problem with the chunks representing the Terminator-style texts because those were the resources about to be called when the game crash occurred. Interrogation of RawCompChunks showed that NextGenGraphics was not changing the decompressed size of any chunks, but one of the two Terminator text chunks was immensely larger than the other. Even more suspiciously, the entry for the smaller chunk was claiming to be the same size as a masked tile.

The problem was that I had configured chunk settings wrong in all my tests. I must have miscopied MaskTileEnd as I was transcribing the settings from the old GalaxyGraphics format; the mistake was replicated into all my testing methods. Setting the correct end of masked tiles (which have a fixed decompressed length and therefore don't get the heading UInteger) fixed the crash. Everything else appeared to be working correctly.

Tomorrow, I'll see if the image serialization code I wrote yesterday actually works.

No comments:

Post a Comment