August 23, 2026
How I fixed a 41 year old bug in Spacewar
I’ve been looking at how the old 1985 Dos game works, and how I can modify it.
By Diederik Hattingh
2 min read
As I was playing with one of the modifications, I noticed a strange ship duplication bug. Or as I called it the "ghost ship bug".
The game is only supposed to have two ships. Steering wheel design A and steering wheel design B. That's it. Cloning is not allowed. THIS ISN'T CHINA!
As I was running a modified version of the game, I thought my changes broke the game somehow.
Send in the robots
I asked Codex to take a look. We first went down the wrong rabbit hole: It did a valiant attempt in instrumenting the dosbox debugger, and the game itself. But after 5 runs it gave up.
I then proposed an alternative. Let the slow human (me 🤓) drive the game rounds, while we modify the game executable to keep some game state in memory. Then once I see the bug manifest, we can pause the debugger, dump the state to a file for further inspection.
Quick detour to 1991
As I said, I remember vividly playing this game back in the day. And this bug has come up. My friend and I were playing side by side, trying to kill the each other, and then I saw 2 of his steering wheel style ships…
Luckily my extremely sharp and quick thinking mind said, "I should probably just shoot the ship that is actually moving, and shooting at me. Instead of the decoy."
He played the game more than me, and I simply thought he triggered a clone ship command that I didn't know about.
Not quite an off-by-one error
The bug originated in the ship hyperspace routine. It works as follows: The user presses the hyperspace button. The ship is then hidden. 32 stars are then rendered on the old spaceship location. A random new ship location is then selected. The 64 stars are animated from the old location, to the new location in an explosive/implosive animation.
After the animation completes, the ships is drawn again, and play continues.
The bug happens when the round ends, and the hyperspace animation didn't complete.
As you can see from the above video, the round got ended (pressed F1) before the hyperspace animation got a chance to complete. It tires to complete the animation on the first bit of the second round.
So the fix was quite simple: Just zero the hyperspace animation counters on round start.
Once you understand the bug, its easy to fix.
Would I have shipped with this bug?
I suspect this bug was probably found in testing in 1985, but was deemed not worth fixing. If you play a computer player, and die early, you have a fair chance of stepping on this bug — as they really like hyperspacing. It is a bit like playing against a grasshopper.
And since the animation's counter does get to zero in the buggy round, the next round should fix itself.
Either way, the fix can be found here if you are interested.
Happy bug hunting all. 🐞