Wednesday, July 16, 2014

FMod - File Handle Confusion

The wonderful Bio Menace modder who appeared on the Keen:Modding forums a while ago has given me some help with Abiathar. He reported a crash-corruption bug (!) involved with copying tiles. Though that particular instance of task was not really suited for the copy/paste mechanism and he was actually triggering entirely different functionality than what he wanted, there was still quite a bit of a problem in the program.

He was pressing Enter, probably thinking that it completes the copy, but it actually causes the graphics to reload, like in Mindbelt. That function was causing an IOException to be thrown, citing a file handle being open in another process. I looked all throughout the graphics loading code to find a leaked handle, even liberally sprinkling Using blocks around IDisposable instances. I did that for almost an hour until I discovered that something was wrong in the reload-graphics wrapper, not the graphics loader itself. After the call to DestroyGraphics, the reloader explicitly created handles for the EGA resources! That was an artifact from before bitmap graphics were allowed, and it was definitely the cause of the error. I removed them (they were just throwing the handles away anyway) and the problem was solved.

Also, I did some better clean-up of the selection plane so that it does not show the previous selection in a level when you switch back to the copy tool after canceling a copy.

No comments:

Post a Comment