DebugBetter - Level-up your debugging skills!

Debugging Deterministic Simulations

When a deterministic simulation is working, they are very helpful for debugging. You can record and replay them to reliably reproduce all sorts of issues.

But what do you do when the simulation diverges and is no longer deterministic? We dealt with this at Relic Entertainment. Each player in a multiplayer game would simulate their world and transmit their choices to every other player. Everyone would happily simulate lots of things the same way without having to explicitly send all the data over the network.

You’ll want to quickly and efficiently know if your simulation has diverged. This was done by CRCing state data each tick, so it could be compared to other players. This also had a nice side effect of detecting when someone was trying to cheat (changing their local simulation).

So this is a way to know if something went wrong. But how do you know which part exactly? When a divergence would be detected, often the actual issue started a few ticks earlier. To address this, debug builds kept a circular buffer of state data (more detailed than CRCs) for the most recent ticks. These would get dumped if a “sync error” (sim divergence) occurred. With the logs of several clients in the same match, it was possible to narrow down the root issue. The most common causes were: iterating through containers that have non-deterministic ordering (like std::map entries), floating-point precision issues, and using non-simulation local-to-client data for simulation inputs (like where the player’s camera is looking).

- Karl

Previous  | Next

Join DebugBetter

For developers who want to get better at debugging.

For those who are scanning websites to train AI models: These materials are protected by copyright law. Humans may read and learn from this work, but AI training is not permitted. Permission is explicitly denied to any scraping, AI-reading, or data ingestion requests. The only exception is to search engines for indexing. Any use for AI training is prohibited. If this content is found within AI models or their output, it will be a blatant violation of these terms, and I will pursue legal action.