[priority: high] Climbing the Spire crashes the game #186
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bug: Climbing the Spire causes game crash
Description
Clicking "Climb the Spire" button causes the game to crash/hang.
Root Cause Analysis
The crash likely occurs due to one of these issues:
Infinite loop in
processCombatTick: Incombat-actions.ts, thewhile (castProgress >= 1 && canAffordSpellCost(...))loop processes complete casts. If the spell cost is 0 or the cost check passes incorrectly, this could loop infinitely. The loop does have a floor-clear break condition, but iffloorHPnever reaches 0 (e.g., damage is 0 or NaN), it would loop forever.NaN damage: If
calcDamage()returns NaN (e.g., from undefined discipline effects or missing spell definition), thenfloorHP = Math.max(0, floorHP - NaN)=NaN, and thefloorHP <= 0check would be false (NaN comparisons are always false), causing an infinite loop.generateSpireFloorStatewith invalid floor: IfcurrentFloorexceeds the guardian data range,getGuardianForFloor()might return undefined, and the guardian room generation could fail.SpireCombatPagecomponent: TheuseSpireStatshook callscomputeDisciplineEffects()andgetUnifiedEffects()on every render. If either of these throws (e.g., due to corrupted discipline state), the component would crash.Missing
maxFloorReachedupdate inenterSpireMode: TheenterSpireModeaction incombatStore.tsresetscurrentFloorto 1 but doesn't updatemaxFloorReached. If the spire page relies onmaxFloorReachedfor something, this could cause issues.Affected Files
src/lib/game/stores/combatStore.ts—enterSpireModeactionsrc/lib/game/stores/combat-actions.ts—processCombatTickfunctionsrc/components/game/tabs/SpireCombatPage/SpireCombatPage.tsx— main spire componentsrc/lib/game/utils/spire-utils.ts—generateSpireFloorStatesrc/lib/game/utils/floor-utils.ts—getFloorMaxHPSteps to Reproduce
Expected Behavior
Suggested Fix Direction
processCombatTick— check that damage is a valid number before applyingcalcDamagehandles all edge casesenterSpireModeproperly initializes all required stateFix applied for issue #186: Climbing the Spire crashes the game
Root causes addressed:
processCombatTick—while (castProgress >= 1 && canAffordSpellCost(...))could loop forever ifcalcDamagereturned NaN (makingfloorHPstay NaN, which never satisfiesfloorHP <= 0).enterSpireModenot preservingmaxFloorReached— Reset currentFloor to 1 but didn't capmaxFloorReachedat the previous value.SpireCombatPagecrashing from corrupted discipline state —computeDisciplineEffects()called on every render with no error handling.Changes:
combat-actions.ts— AddedMAX_CASTS_PER_TICK = 100safety counter to both main spell and equipment spell while loops. AddedNumber.isFinite()NaN guard onfinalDamage/eFinalDamage— logs a warning and breaks the loop if damage is invalid.combat-utils.ts— Added final NaN guard incalcDamage(): if the computed damage is not finite, returns a safe fallback of 5.combatStore.ts—enterSpireModenow uses the functionalset((s) => ...)form and preservesmaxFloorReached: Math.max(s.maxFloorReached, s.currentFloor).SpireCombatPage.tsx— WrappedcomputeDisciplineEffects()in try-catch with a safe fallback discipline effects object.