Code Room
Vibe codingHardvc-g362
Subject Ai code reviewLevel Senior–Staff~19 minCommon in Algorithms & data structures interviewsIndustries Computer games, Software development

Question

An AI assistant hand-rolled the main loop for a C++ engine using a fixed-timestep accumulator. On fast machines it's smooth, but on a slow laptop the game enters a death spiral and freezes once physics gets expensive. Review the loop and explain the failure mode.

cpp
while (running) {    double now = Clock();    double frameTime = now - last;    last = now;    accumulator += frameTime;    while (accumulator >= FIXED_DT) {        Physics::Step(FIXED_DT);   // can itself take longer than FIXED_DT        accumulator -= FIXED_DT;    }    Render(accumulator / FIXED_DT);}
What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it — tests, edge cases, reading critically — and how you’d re-prompt or decompose to get it right.

Describe your solution

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.