Jesus
The bug was so uncommon that we even had an inner meme — “This is not a bug, it is the start of a brand new faith within the recreation.”
The issue remained a whole thriller. For six months, I couldn’t catch the bug — I merely could not reproduce it it doesn’t matter what I attempted.
Later, I launched models with an prolonged line of sight — 25 tiles as a substitute of the usual three — to make testing simpler. With such a large view, it turned a lot simpler to look at every thing taking place on the planet, together with AI conduct.
I went via all of the code and double-checked each algorithm associated to unit motion throughout the map. I discovered no points — and nonetheless, I could not reproduce the bug.
Then, whereas making ready screenshots and gifs for the sport’s Steam web page, I made a decision to extend the models’ line of sight even additional — as much as 50 tiles.
And that is when the bug began to pop up far more ceaselessly.
In the course of the seek for lovely areas for media content material, I needed to regenerate maps repeatedly.
And solely throughout this sequence of fast map generations, with out restarting the sport via the IDE however merely going again to the primary menu and producing once more, I lastly caught the bug in motion.
At that time, a sample turned clear:
Normally, I’d launch the venture from the IDE, generate a map, take a look at just a few issues, exit the sport fully, and restart.
However when regenerating maps with out leaving to the desktop, the bug appeared constantly.
All server-side world interactions handed via a worldwide singleton: ServerContainer.
When a brand new server was launched for a brand new map, the outdated ServerContainer remained, retaining outdated hyperlinks to models and map knowledge — resulting in this damaged conduct.
Fortunately, I already had a cleanup() methodology inside ServerContainer, which was speculated to clear all crucial knowledge after exiting a recreation session. Some sources (like cached templates and configurations) have been deliberately preserved to hurry up new world technology.
After which it hit me — the trigger was apparent:
I merely forgot to name cleanup() when exiting the server session.
Lesson discovered: Do not make errors like that!
Wishing you all easy code and nice temper!