One Frame Behind Forever — Java Bug Hunt
Inspired by the fixed-timestep game loops described in every "Fix Your Timestep!" postmortem: the accumulator pattern must run whole simulation frames and…
- Language: Java
- Layer: Frontend
- Difficulty: Hard
- Concepts: Game Loops, Rounding
- Modelled on: Game engines
- Visible tests: underfunded frames do not run; full frames run with exact remainder; exact multiples leave zero remainder
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-2
- Time to fix: 35 minutes, the target for a hard incident
Failing checks on the shipped build
- underfunded frames do not run — 15ms cannot fund a 16ms frame: expected [0, 15] but got [1, -1]
- full frames run with exact remainder — expected [2, 8] but got [3, -8]
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Inspired by the fixed-timestep game loops described in every "Fix Your Timestep!" postmortem: the accumulator pattern must run whole simulation frames and carry the exact remainder. Round instead of floor, and the simulation runs frames it hasn't earned — leaving a negative time debt that compounds into stutter.
GameLoop.java computes frames-to-run from the accumulator.
Bug report
BUG-TIMESTEP · Reported by: engine team
framesToRun(accumulatorMs, frameMs) -> int[]{frames, remainderMs}:
- frames = floor(accumulator / frame) — only FULLY funded frames
- remainder = accumulator - frames * frame (always 0 <= r < frame)
Observed: 15ms of accumulated time runs a 16ms frame — remainder -1ms. The debt snowballs and the camera micro-stutters forever.
Logs
[loop] acc=15 frame=16 -> ran 1 frame, remainder -1The code as shipped
GameLoop.java (editable)
class GameLoop {
static int[] framesToRun(int accumulatorMs, int frameMs) {
int frames = Math.round((float) accumulatorMs / frameMs);
int remainder = accumulatorMs - frames * frameMs;
return new int[] { frames, remainder };
}
}Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Java bug hunts.