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

Question

An AI agent extended a custom ECS by adding a system that spawns new entities (projectiles) while iterating the shooter set, and registers them so they're processed THIS frame. Players report newly-spawned projectiles sometimes have garbage transforms or are skipped for a frame. Review the system and explain the iteration/registration bug.

cpp
void ShootSystem::Update(World& w) {    for (Entity e : w.View<Shooter, Transform>()) {        auto& s = w.Get<Shooter>(e);        if (s.wantsToFire) {            Entity p = w.CreateEntity();                 // grows the entity arrays            w.Add<Projectile>(p, MakeProjectile(e));            w.Add<Transform>(p, w.Get<Transform>(e));    // copy shooter transform            // (View<Shooter,Transform> now includes/excludes p mid-iteration?)        }    }}
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.