Friday, June 28, 2013

The inevitable bug fix release

After releasing a version with new features, it turns out it also contained 1 show-stopping bug. To fix things, 1.15 of Chaos is out.

Enabling constant saves fell foul of a memory leak in the bit of code that bridged the Android stuff and the older C code. This meant that the game crashed after about 5-10 minutes of playing. My testing obviously wasn't thorough enough.

I've resurrected the stress-test mode on the debug builds of Android now (CFLAGS=-DHAS_STRESS_TEST, configure-fans). In the last release this didn't even compile. Shows how naffly tested it was. I ran the stress test on the SDL/PC version, but not on Android. These versions share about 90% of the code, but the bug was right in the Android glue that only running the game on a device or emulator can test.

The stress mode pits 8 computer-controlled players against each other with no hold-ups, forever. Or until there's a crash at least. Things are looking a lot better now, as it has run for hours with no crashes since the fix. Previously it wouldn't get past about 6 minutes of play.

The fix was a classic memory leak. I needed to delete arrays allocated in the C code.

JNIEnv *env;
jbyteArray jb;
int size;
/* allocate a new byte array */
jb = (*env)->NewByteArray(env, size);
/* do stuff with jb ... */
(*env)->DeleteLocalRef(env, jb); /* !! this was missing */

I had misunderstood who was responsible for this allocated memory. I thought that the virtual machine's garbage collection took care of it, but the evidence indicates that it requires manual intervention.

Lessons learned: 1) automatic tests are great, 2) but not if you don't run them!

Monday, June 17, 2013

Chaos 1.14

The last time I updated Chaos was well over a year ago, so it was about due for an update.

As well as the usual bug fixes, this release has one new feature: automatic saving. Players have asked for this both by email and on the comments in the Android market for a while and it makes quite a difference.

At the end of every turn, the game is now saved. If the game is stopped then next time you start there's a "Continue" option on the first screen.


I've also updated the GBA and NDS versions to include this restore feature. Whether or not saves actually work can depend on the flash cart you use, so watch out for that.

The game saves all data in a plain text format that you can copy around. I've changed the way options are saved to also use text. Previously I just dumped out the in-memory representation for the options into a file. This should fix the problems that people have had where sound effects don't work - in fact they were disabled by default. It was due to reading a 0 first time round and this disabled the sound option.

--

Another change is that the source code for the game is now available again.

The state of Android over the last year or so has worried me. It has become a wretched hive of scum and villainy rivalled only by the dark days of the Windows 98/XP platforms.

The best way to prevent falling victim to spyware is to use software where you can audit the source code yourself. Or at least say "no" when programs require extra permissions. Chaos requires no extra permissions and now you can review the code too.