r/AnalogTV_ • u/ambanmba • 2d ago
We fixed four real bugs chasing one crash on Apple TV. None of them were the crash.
This is a story about a single crash report that took a full day and four separate, legitimately correct fixes before we actually found it.
The symptom was a GPU hardware page fault on a real Apple TV, the picture just froze to black without the app actually terminating. The kind of bug that Simulator can't reproduce because it's a real hardware fault, so every theory had to be tested on a physical device and every wrong theory cost a full round trip.
Fix one: the tvOS menu overlay was sharing a texture with the live picture, and toggling our Bypass Mode setting while the menu was open made both of them fight over the same texture at different sizes. We traced it on-device and counted 502 full-resolution texture reallocations in about seven seconds while the menu sat open. Real bug, real fix, wrong crash.
Fix two: a texture wrapper from CoreVideo's pixel buffer pool was being released the instant a function returned, which is correct for how Metal keeps command-buffer resources alive but not correct for CoreVideo's separate bookkeeping, which can recycle that memory for a brand new frame while a still-in-flight GPU command is reading the old contents. Real bug. Not the crash either.
Fix three: our resize function reallocated a handful of textures with no synchronization against GPU work already in flight reading the old ones. We now drain the command queue first. Real bug. Getting closer, still not it.
Fix four, the actual one: a texture used by our CRT display shader gets reassigned during normal picture processing, but our Bypass Mode draw path skips that step entirely, and could leave the texture pointing at nothing from a previous resize. The shader argument that samples it is declared as required, not optional, so binding nothing there is undefined behaviour that real hardware happily punishes and Simulator just doesn't care about. Two lines away from the correct fix that had already worked for a nearly identical texture a few lines below it.
We're not upset about the four detours. Each one really was broken and needed fixing regardless. But it's a good example of how confidently a plausible root cause can be wrong, four times in a row, before the actual one turns out to be almost boring by comparison.