ThrusterInstanceManager.unregisterSpacecraft never reclaims instance slots #1033

Closed
opened 2026-08-13 05:02:46 +00:00 by spikerj · 1 comment
Owner

Discovered while writing characterization tests for projects/spikersoft/src/app/_components/_games/space-game/spacecraft/thruster-instance-manager.ts (wave 7 coverage).

What happens

registerSpacecraft advances nextInstanceIndex by the thruster count. unregisterSpacecraft hides those instances (scale-0 matrix + zeroed thrusterStates) and deletes the registration, but does not decrement nextInstanceIndex or recycle the freed range.

A spacecraft that despawns and respawns therefore consumes a new block of the 24×N InstancedMesh pool. After enough spawn/despawn cycles the manager hits Out of instance capacity even though no live spacecraft occupy the earlier slots.

Repro (characterization, already pinned)

  1. getInstance(1) → 24 slots.
  2. registerSpacecraft(1, …) → indices [0].
  3. unregisterSpacecraft(1).
  4. registerSpacecraft(1, …) again → indices [1], not [0].

Expected

Unregister should return the range to a free list (or compact nextInstanceIndex) so a re-register reuses the old indices.

Pinned as a characterization test in thruster-instance-manager.spec.ts so the suite stays green until this is fixed.

Discovered while writing characterization tests for `projects/spikersoft/src/app/_components/_games/space-game/spacecraft/thruster-instance-manager.ts` (wave 7 coverage). ## What happens `registerSpacecraft` advances `nextInstanceIndex` by the thruster count. `unregisterSpacecraft` hides those instances (scale-0 matrix + zeroed `thrusterStates`) and deletes the registration, but **does not decrement `nextInstanceIndex` or recycle the freed range**. A spacecraft that despawns and respawns therefore consumes a *new* block of the 24×N InstancedMesh pool. After enough spawn/despawn cycles the manager hits `Out of instance capacity` even though no live spacecraft occupy the earlier slots. ## Repro (characterization, already pinned) 1. `getInstance(1)` → 24 slots. 2. `registerSpacecraft(1, …)` → indices `[0]`. 3. `unregisterSpacecraft(1)`. 4. `registerSpacecraft(1, …)` again → indices `[1]`, not `[0]`. ## Expected Unregister should return the range to a free list (or compact `nextInstanceIndex`) so a re-register reuses the old indices. Pinned as a characterization test in `thruster-instance-manager.spec.ts` so the suite stays green until this is fixed.
Author
Owner

Fixed in spikersoft-angular PR #823 (a0f0ccd9). Closing.

Fixed in `spikersoft-angular` [PR #823](https://git.spikersoft.com/spikerj/spikersoft-angular/pulls/823) (`a0f0ccd9`). Closing.
Sign in to join this conversation.