Another bug hunt

One of the features that I have always planned for DWJukebox is the  ability to switch skins on the fly.  The main reason for this was to support systems with rotateable monitors, cocktail-style arcade cabinets or any others that may need more than one orientation available.

Since I’ve designed for this possibility from the beginning, adding the feature would theoretically be simple.  All I need to do is hook up a key message, use that to terminate the existing skin without setting the shutdown flag, then loading the new skin.  Piece of cake, right?

However, I’ve been avoiding this feature for ages, and the reason for that is simple.  Fear.

The skin loading code is the most complicated programming I’ve ever done.  To allow for all the flexibility, everything is dynamic, and memory for everything must be allocated dynamically.  In addition, with the rotation and flip options and the ability to support any resolution, there are a lot of temporary scratchpads that are created and deleted as the skin loads.  I knew that unloading all of these allocations cleanly and loading a completely different set was going to be a serious test of the watertightness of my code.

Boy, was I right.

The moment I attempted to switch skins, all manner of memory exceptions and crashes spewed forth as I opened up Pandora’s box.  I spent many hours slogging through them over the weekend, tracking down memory leaks, corruptions, dangling pointers, and all manner of memory mayhem. 

In the end, however, it will all be worth it.  I have gotten many support requests and crash reports that all pointed to a likely answer of a memory issue somewhere.  It is likely that the problems keeping skins from switching properly are the same problems causing all of these other strange and difficult to reproduce crashes.  As I crawl through the code looking for the problems, I’m adding more logging, simplifying pieces of code written long ago, and performing a lot of other bits of maintenance that will hopefully solve most of the “instability” reports I’ve been getting.