monkeylashes

Learnings

Lessons I learned the hard way, usually after a bug cost me a day or two. I keep them all in one place because most of them apply well beyond the project they came from.

Diablo II: Resurrected in VR

About this project →
Anything that measures the frame loop is part of it
Twice now, the thing watching the frame was the thing slowing it down. In the first preview, the log was flushed to disk synchronously from code that runs every frame, and buffering it made the hitches better. Later, the CPU diagnostics I'd added to chase stalls took a snapshot of every thread on the system inside Present, every ten seconds, and held up rendering for about 53 ms each time. That kind of stall is hard to catch because it's regular enough to look like the game, and it shows up in every capture you take to find it. Anything that watches a frame-locked loop uses up that loop's time, so it belongs on another thread.
If the problem survives a rollback, it isn't in what you rolled back
The Linux build kept stalling after I rolled the mod back to an earlier DLL and rebooted the PC, and a freshly started SteamVR logged 119 stream-reset requests before the game was even running. Neither of those tells you the cause. Together they tell you where it isn't, which was the code I'd just rolled back, and that stopped me from spending time tuning something that was never the problem.
A pinned checksum pins the archive, not the files inside it
A dependency got re-zipped upstream under the same filename and version. The four files inside were exactly the same, but the archive's hash changed, so every fresh install refused it, which is what it should do. The tricky part was who could see it. Any machine that had installed before still had the verified archive cached and never downloaded it again, so the people most likely to be testing the installer were the ones it couldn't fail for. The fix was to check the new archive and accept both hashes, and keep checking.
Hiding part of an old game's interface can break things it did besides drawing
When I took the flat HUD out of VR, its belt widget also stopped linking the belt to the player. The game's potion command kept returning "handled", so the drinking gesture was accepted and nothing got drunk, because the belt had no owner. Calling the game's own setter before the command fixed it. In an engine that was never meant to run without its interface, the interface holds state, and a success return only tells you the call went through. It doesn't tell you anything happened.

Homeworld: Unbound

About this project →
If the whole scene looks flat, check the color pipeline before the lighting
Ships looked flat, like they were lit from every direction, but the shading code was fine. I was handing the swapchain linear color and it was treating it as sRGB, which brightens every mid-tone and pulls the shadowed side of a ship up toward the lit side. The giveaway was that the whole scene was affected evenly. One bad model usually means bad normals. Everything flat at once means the pipeline.
Be careful hooking your frame into a function that's called from elsewhere
The VR frame runs off the engine's rndFlush, which I did on purpose. But the loading bar also calls rndFlush every time it moves, so each tick of the progress bar rendered a full stereo frame while the game was halfway through freeing and reloading every texture. Leaving any mission through hyperspace crashed fifteen frames deep in the renderer, nowhere near the VR code that caused it.
Helper functions can have side effects that undo your work
To build the game camera on its own, I called the engine's rgluLookAt with an identity matrix. During an eye pass that helper also multiplies in the headset pose, so the matrix I thought was clean still had the head in it. The render then cancelled the head movement out against itself, and anything that doesn't respond to head movement looks glued to your face. That's exactly how it looked.
Two reasonable numbers can still break each other
Flight paths I drew disappeared the moment I committed them. Waypoint spacing was the path length divided by twelve, and the arrival radius was three hull widths plus a tenth of the world scale. Each made sense on its own. But a drawn stroke is about a meter of arm movement, so the arrival radius was bigger than the gap between waypoints for almost any path you could draw, and the ships used up the whole route in twelve frames.
Turned-off compiler warnings can hide real bugs
The build passes -Wno-implicit-function-declaration, inherited from the 1999 code. So when code called an undeclared function that returns a float, the compiler silently assumed it returned an int, and the distances came out as garbage. It compiled clean and ran wrong. Old codebases have good reasons for their warning suppressions, but you end up paying for them later.
Only compare log lines from the same frame
I made three wrong diagnoses in a row by reading two debug lines that were ninety seconds apart as if they described the same moment. What finally found the bug was a single value that should have been exactly zero for a game camera and wasn't. One line, consistent with itself, that didn't need anything else to make sense.
A version number that never changes is worse than none
For seven releases the APK said it was version 1.2.0 build 1. That was the version of the engine I built on, and I never touched it. Sideloaders and app stores use that number, and only that number, to decide whether a build is newer, so none of those seven releases ever registered as an update anywhere. A missing version number would have made someone ask questions. A plausible one just gets trusted.
Removing every known obstacle isn't the same as testing it
Relaying traffic through the host removed every problem I knew of with playing over the internet with more than two people, and I was tempted to call that working. But I'd never played a game with three machines on three different connections, so what I could actually say was smaller: two players is tested, three should work. The bug reports usually come from the gap between those two.
Test on a network that can actually show the bug
One release shipped internet multiplayer with three separate bugs, and all three mixed up the address a machine calls itself with the address other people can reach it at. On a local network those are the same, so none of the three could show up in my testing. The LAN wasn't just a weak test, it made the two values identical, which guaranteed the bugs would get through. It's worth asking what your test setup makes identical that won't be in the real world.
Recheck old defaults when the display changes
Smoothing on the ship textures was a fine default for a 1999 monitor, and it carried over untouched into a headset that blows a 64x64 texture up far beyond anything its artist had in mind. The setting stayed the same, but it went from a small finish on the ships to most of what you were looking at. When the output changes that much, every default picked for the old one needs checking again, including ones nobody has thought about in twenty-five years.
When most of a feature works, you look for the bug in the wrong place
Saving a new game failed with "check disk space" on any install where the saves folder had been copied over by hand. The disk was fine. The folder was readable by the game but not writable. Everything that would have pointed at permissions worked: saves showed up in the list and loaded fine. Reading a folder and creating a file in it are separate permissions, so only the narrow case broke, and a bug that leaves most of a feature working doesn't look like a permissions problem.
Read game data from wherever the player can put it
The game read its data from one protected folder, so getting files into that folder was the setup step. Android 11 had locked that folder away from every file manager on the headset, so the only way in was a second computer connected over adb. The instructions looked like "copy three files" and really meant "own a PC". Searching the places a person can actually write to, and reading the files from there, got rid of the whole procedure. For any setup step you walk people through, it's worth asking whether it only exists because the program wants files in one particular place.
Players know which workaround is actually a dealbreaker
Copying the files across had been part of every release, and I knew it was awkward. It took a player on r/OculusQuest to point out that this was the thing stopping the port from being usable on the headset alone, and to show me how other ports had solved it. From the inside, a known rough edge and a real barrier look the same, because I'd already worked around both and stopped noticing them.
An emulated device only answers the questions you thought of
My stand-in for the mouse answered "where is the pointer" well enough that the wrist panel worked. But once a drag starts, Homeworld stops asking where the pointer is and starts asking how far the mouse has moved, and there was no mouse to have moved. So pressing worked and dragging silently did nothing, in every build for a month. An emulated device is just the set of questions someone thought to answer, and the gaps are wherever the real hardware got asked something else.
One rule for everything goes wrong on the thing that's different
I put every one of the game's screens on the wrist panel. That's right for Build and Research, which are lists of ships and costs, and a flat panel is a good place for a list. The Sensors Manager is a 3D scene with its own camera, though, and flattening it was the one place that choice cost something. The rule was fine. I'd just applied it to something it didn't fit, which is harder to spot because the rule still looks right.
On a headset, a crash at startup looks like a hang
A crash on startup showed up as an endless wait in the headset's loading environment. The compositor keeps showing its own room until an app gives it a frame, and an app that dies before its first frame never does. On a desktop a crash at least makes a window disappear. Here there was nothing to disappear, so the only symptom was waiting. It's worth knowing which failures a platform shows you as nothing at all.
A choice made at startup can outlive a restart that never happened
Whether you were playing the demo or the full campaign was decided when the app started, and baked into the engine it loaded. That's fine until Android reuses a process that's already running instead of starting a new one. The app correctly noticed the new game data and then handed it to an engine that couldn't take it. Anything decided once at launch only holds up as long as the platform actually launches again.
Fixing the crash doesn't count if the player still sees the problem
My first fix for a stuck launch stopped the crash, but the process still exited without coming back. Players still saw a stuck loading screen and still had to press launch again, exactly like the bug, and I shipped it as fixed because the log was clean. I should have checked whether the symptom was gone, not just the fault. One is a question about the system and the other is about the person using it.
The first crash you find can be part of a bigger one
A crash when going from the demo to the full game had a complete, correct explanation: the campaign choice is built into the engine, and Android had warm-started the process with the wrong one loaded. But it was one case of a wider problem, which is that the engine can't start twice in the same process at all, whatever the campaign. It just died sooner than the general case, which is why it looked like its own bug with its own neat explanation. I should have kept digging after the first explanation fit.
Skipping a layer also skips whatever else it was doing
The VR controls call the engine directly instead of faking key presses. That's the right call, because otherwise a key the player had unbound would swallow a command without any sign. But the keyboard path had also been triggering the order acknowledgements along the way, so the fleet went silent. In a headset, where the destination is often behind you, that voice line was most of the proof an order had gone through. Nobody writes down the things a layer does by accident, so they disappear along with it.

Medal of Honor: Allied Assault in VR

About this project →
"Supports OpenGL ES" often means it almost does
The renderer was documented as working on GLES, and it couldn't start on it. Its list of GL 1.1 entry points included five functions that don't exist in any version of GLES, and the ES path shared that list, so loading failed on every ES context before a single frame was drawn. Separately, the ES 3.0 context was only ever requested inside an Emscripten ifdef, so everywhere else the driver gave back ES 2.0. Neither bug was specific to Android. Both would already have broken the browser build that was in the tree.
Compatibility layers can hide bugs in their caches
I spent two days on a black screen that turned out to be gl4es answering questions from its own copy of the GL state instead of the driver's, and holding onto a stale cull-face setting. The same kind of bug showed up separately in the Homeworld port, where a cached "texturing is already enabled" flag meant the enable call never got made and a textured quad drew black. Translation layers are fast because they cache, and they're confusing for the same reason.
Being part of the spec doesn't mean it's turned on
Framebuffer objects are core in ES 2.0, but the renderer still disabled them on GLES with an early exit that left the whole entry point table null. They're worth loading, but I keep the renderer's own use of them off in VR on purpose. Each eye is already a swapchain image, so going through an extra framebuffer first costs a second full-resolution pass and resolve per eye, and gets you nothing.
Let the engine create its own directories
A save folder made with adb belongs to the shell user, and no chmod makes it writable by the app, which only counts as "other" there. MOH:AA autosaves the moment a mission starts and treats a failure as fatal, so the symptom is a black screen after New Game and one log line about a path it couldn't create. I hit the same trap in a different form on the Homeworld port too.
Make sure the renderer can draw anything before trusting a failed test
For a whole session the graphics layer couldn't draw anything at all, and every experiment I ran on top of that gave the same answer, nothing on screen, no matter what it was testing. I drew five conclusions from that broken baseline and acted on them: that 32-bit indices were at fault, that a draw path was broken, that compiled vertex arrays were broken, that a buffer call was throwing everything away, and, at two different points, that immediate mode both did and didn't work. All of it got thrown away. The check that finally cracked it takes a minute: ask for a screen clear, then one flat untextured quad, and read the pixels back. A clear doesn't need shaders, and a quad needs the whole pipeline. If the clear shows up and the quad doesn't, stop looking at the engine.
Debug probes can stop running without telling you
I had a diagnostic probe that only ran under a condition, and an unrelated change made that condition false without me noticing. Two more rounds of "nothing was drawn" were really "the probe never ran". You can't tell those apart from the outside, and they sent me the wrong way. Whenever something a probe depends on changes, I need to check it still reaches the thing it's supposed to measure.
A library can report success and still leave you unbound
In a headset there's no window surface, and SDL still hands back a live OpenGL context and reports success without actually binding anything. Its own bookkeeping then says the context is current, so asking it to bind again returns early, and SDL and the driver disagree from then on. It got worse because the compatibility layer answered version queries from its own constants, so the engine's only check that the context was alive passed every time, against a context that had never been bound. The fix is what other Quest ports do: bind against a 16x16 offscreen buffer that exists only so there's something to be current on.
Repeat a result before building on it
The same configuration gave different results on different runs more than once, and I'd built a bisect on top of that before I noticed. Changing code and configuration in the same step wiped out my only known-good baseline, and it took several rounds to get it back.
A newer renderer is only faster if the game's art can use it
rend2 ran this game at 10 to 15 fps, and the GPU wasn't the problem: it finished its work in 3 ms. The cost was 50 to 60 ms of CPU per eye, binding GLSL programs for lighting that art made in 2002 has no maps for. The older fixed-function path only asks the content for what it actually has, so it wins here, and VR makes the gap bigger because any cost per eye gets paid twice. Newer rendering paths expect newer assets, and a port is stuck with the assets the game shipped with.

33 learnings across 3 projects.