We all love bugs they are like nuggets of entertainment for programmers that sit roughly between the extremes of love and hate. There are some bugs however that years after they have been squished still come to mind, indeed ask any engineer about bugs and he / she will undoubtedly have a story or two to tell.
One bug that I thought worth sharing relates to a streaming game where if you walked a specific route from room A to B to C to D and finally to E you would find a book lying on the floor in the centre of the room. Loading into room E directly would not generate the book and looking at room E in the editor showed that the room itself didn’t contain any books. After a few tests walking different routes it seemed obvious that it was only that specific route that generated the offending object.
With the exception of “The Big Bang” things don’t generally pop into existence for no reason and this bug for me falls into the “Love” category. I also tip my hat to those chaps and lasses in QA that not only managed to find this but also managed to work out how to reproduce it.
The clue to solving the bug came when I happened to notice that the object was sitting at the origin (0.0f ,0.0f ,0.0f), and as I soon learned Room E was at the centre of the streaming world. The world origin in my opinion is the Bermuda triangle of games, strange things happen there and everyone would be better off wearing protective eyewear when looking directly at it.
In a lot of systems, the creation of game objects very rarely pop into existence all initialized and ready to rock and roll, usually there is a stage where an objects data is undefined (random) or cleared (zeroed) because of this every game object generally exists at the world origin at one point or another regardless of how briefly.
The evidence, a streaming object is being created it’s visuals were being initialized but for some reason the last part of actually setting it to it’s correct position was failing. It didn’t take long to track it down, turns out that the physics setup for this specific book was bad which meant that the creation of the physics failed. This then lead to the position and orientation never getting set leaving the book at the world origin. The book was actually part of Room B but because it failed to initialize it never got cleaned up when that room was unloaded (very dangerous in a streaming environment).
An hour later, the following changes were made:
- The books physics data was fixed.
- The position of an object is set regardless of success / failure of other systems.
- If a failure occurs in initializing a system (i.e. Physics) a very loud assert fires!
As I said earlier strange things happen at the origin I and quite a few other developers used to store un-used objects at the origin, the running joke being don’t look under the floorboards which was generally where the origin existed. I stopped using this as a storage point however when I started using physics engines and objects started interacting with each other pinging themselves through the floor into the gaming environment. Hilarious the first time it happened but ultimately I lost my easy storage point.