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!