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

Question

An AI agent implemented a damage-resolution system for a custom C++ ECS. Under load — many overlapping AoE hits — the game crashes intermittently and sometimes a unit takes damage twice or skips its death. Review the system and explain the structural bug.

cpp
void DamageSystem::Update(World& world) {    auto& healths = world.GetComponents<Health>();    for (auto& [entity, hp] : healths) {        hp.value -= IncomingDamage(entity);        if (hp.value <= 0) {            SpawnCorpse(world, entity);          // adds Corpse + Transform components            world.RemoveComponent<Health>(entity); // mutates the map we are iterating        }    }}
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.