Friday, January 03, 2025

Flatspace Upgrades

Well, I had thought I'd fixed the Flatspace IIk bug. It was fixed (ie. failed to crash!) in one save, but trying another save caused a crash at Game Over. I painstakingly traced it by outputting a line in a text file at specific points, and I eventually narrowed it down to deletesprite(), a core part of my game engine.

This was a bit of a surprise, as the code there hasn't changed much since 2002 and the first Flatspace game. More odd is that it shouldn't ever crash. The program cycles through all sprites, and if they have a flag of zero (which means 'dead'), the pointer to that sprite is passed to the delete routine. In that routine, all sprites are searched again to locate that pointer. We know the sprite is there and that the pointer is valid, but for some reason, it didn't seem to work, as though it were searching for a sprite that wasn't there...

Odd in many ways, not only in that it had worked fine for 22 years. Perhaps the sprite had been deleted by using some advanced forward-looking logic in a modern CPU, that it had been deleted before the code even saw it. Or the lack of a NULL pointer check (I didn't think I needed one) made the system refuse to look further just in case... but ultimately, the fix was as simple as adding that check, which is good practice anyway.

From:
for (lplpsprite=&startsprite; (*lplpsprite)->next!=lpinput; lplpsprite=&(*lplpsprite)->next);

To:
for (lplpsprite=&startsprite; ((*lplpsprite) && ((*lplpsprite)->next!=lpinput)); lplpsprite=&(*lplpsprite)->next);

The fix seems to have worked. There were are few similar iterative loops that used the same sort of code, so I changed those too. Then I discovered that I'd made this deletesprite() fix in my game engine some time in 2020, but had failed to pass it on to Flatspace. This means that some games; Gunstorm 1 & 2, Bool, Firefly, and Taskforce, probably don't need updating; but Future Pool, Future Snooker, and Argus, should be. Radioactive and Yinyang are too old to need the update. They date from the DirectX6 era and used an array of sprites rather than a linked list (much easier to program with, but far more memory hungry; Radioactive holds over 300 sprites in memory at all times).

The updates to Flatspace and Flatspace IIk have taken all day. I took the opportunity to fix some of the GUI problems in both games, to upgrade the Steam Store graphics with double resolution, and update lostinflatspace.com, which I hadn't touched in about 2 years.

What a waste of my precious time and life these troubles are. I seem to waste so many days scrabbling to try to get back to a stable state, a step once attained and now lost by a random act, rather than making actual positive progress. Well, at least I made a few little upgrades. Yeats said that 'the intellect of man is forced to choose perfection of the life or the work' - I'm supposedly free, as free as Leonardo da Vinci, yet am forced to choose work time and time again. I can but do my best by rising early, working late, and doing what is needed as efficiently as I can.

I will wait a day or two to update the other games, while Flatspace is being tested in the real world. Onwards I charge.