This past day has been a real pain. I uncovered two problems that at first seemed to be related. Luckily, experience has taught me that just because two bugs appear similar, it doesn't mean they are caused by the same thing, so I tackled them separately.
Bug #1: Memory LeakI noticed that whenever I'd load a new minigame the memory would jump up by a few megs which, given the number of minigames in Joystick Johnny, would be a problem. I was up to 3AM last night trying to figure out what was going on and couldn't solve it.
Then (as these things usually go) I got up this morning, had my workout, sat down at the computer, and opened up the Blitz docs to the exact page that had the answer I was looking for. The only way I can explain the solution is that I was using a bit of self-referencing in my code, where I assumed the Garbage Collector would take care of it but didn't. (Isn't game development fascinating?)
Bug #2: Game HangingThis one was nuts. Whenever I'd reload a minigame a bunch of times in a row, or if I got close to actually winning the overall game (doh!), it would hang without showing any errors.
After a lot of trial and error, I realized that it was hanging after
exactly the *16th* minigame. (16 being a magical and suspicious computery number, of course.) I finally tracked it down to a call to WaitTimer, which is what makes the game run at a smooth rate. Apparently you can only safely create 16 timers, and I was creating a new timer for each minigame. So I've worked around it and submitted a bug to Blitz Research.