
Only system error beep… How to debug it?

An interesting bug was assigned to me.
There was a system error beep, but…
- Only when starting the game via Steam
- No logs indicated that anything was wrong
- Publishing to Steam was only allowed via our CI system, which took a few hours
How did I approach it?
First, I needed to find a way to iterate quickly. It turned out that I could start the game with cmd.exe to reproduce the issue. It is less convenient than pressing the play button in Visual Studio, but I reduced iteration times from hours to minutes.
Then, I needed to identify the area of the code causing the issue. The mentioned error beep was played during startup, so I started with the in-game startup logic. To determine whether the code part was causing the issue, I added a function call that triggers the functionality of waiting to attach the debugger. If the beep was not triggered, I knew the issue lay further down the line. Exploiting binary search, I quickly found a single function triggering this error beep.
It was SendMessageTimeoutA. The reason for this error beep was an invalid handle to the window (HWND). How was it possible? We retrieved it using the GetForegroundWindow function, but… our game started with the window created but not shown, waiting until the configuration was loaded to determine which resolution we should enforce.
Is such behavior mentioned in the documentation? Not at all.
Delaying sending the message proved to be a quick and easy fix.
To sum up:
- When you do not know where the issue is, start with a binary search
- Documentation does not cover all the cases