fix: GameStateDebug "Fill Mana" loop can freeze UI with large mana values #46

Closed
opened 2026-05-18 16:02:33 +02:00 by Anexim · 3 comments
Owner

Severity: Major

File: src/components/game/debug/GameStateDebug.tsx (lines 95-100)

Problem: The "Fill Mana" button loops Math.floor(max - current) times calling gatherMana(). If max - current is very large (e.g., 100,000+), this will freeze the UI thread for seconds or minutes.

Impact: Potential UI freeze / unresponsive game when using the debug fill mana feature with large mana pools.

Fix: Use setRawMana(max) directly instead of looping:

const fillMana = () => {
  const state = useGameStore.getState();
  const max = computeMaxMana(...);
  useGameStore.setState({ rawMana: max });
};
**Severity:** Major **File:** `src/components/game/debug/GameStateDebug.tsx` (lines 95-100) **Problem:** The "Fill Mana" button loops `Math.floor(max - current)` times calling `gatherMana()`. If `max - current` is very large (e.g., 100,000+), this will freeze the UI thread for seconds or minutes. **Impact:** Potential UI freeze / unresponsive game when using the debug fill mana feature with large mana pools. **Fix:** Use `setRawMana(max)` directly instead of looping: ```ts const fillMana = () => { const state = useGameStore.getState(); const max = computeMaxMana(...); useGameStore.setState({ rawMana: max }); }; ```
Anexim added the ai:todo label 2026-05-18 16:02:33 +02:00
n8n-gitea was assigned by Anexim 2026-05-18 16:02:33 +02:00
Author
Owner

[priority: 4] BROKEN FEATURE — GameStateDebug "Fill Mana" loop can freeze UI with large mana values.

[priority: 4] BROKEN FEATURE — GameStateDebug "Fill Mana" loop can freeze UI with large mana values.
Author
Owner

Starting work on #46. Reading GameStateDebug.tsx to fix the Fill Mana loop freeze.

Starting work on #46. Reading GameStateDebug.tsx to fix the Fill Mana loop freeze.
Author
Owner

Fixed. Replaced the loop-based Fill Mana implementation (which called gatherMana() in a loop up to max-current times) with a direct useManaStore.setState() call that sets rawMana to the computed max. This prevents UI freeze with large mana pools.

Fixed. Replaced the loop-based Fill Mana implementation (which called gatherMana() in a loop up to max-current times) with a direct `useManaStore.setState()` call that sets rawMana to the computed max. This prevents UI freeze with large mana pools.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#46