crit fix: indian subcontinent map crash#4479
Conversation
…nents (e.g. Indian Subcontinent)
WalkthroughThe PR changes water path selection to use ChangesWater pathfinding and map lookup
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/core/pathfinding/algorithms/AStar.WaterHierarchical.ts`:
- Line 316: Add a regression test for the 253+ water-component crash in
AStar.WaterHierarchical by exercising the ConnectedComponents sentinel-width
promotion path and verifying findNearestNode/BFS completes without crossing
land. Use the AStar.WaterHierarchical and ConnectedComponents symbols to locate
the relevant logic, and add a targeted map fixture or mocked map setup that
forces more than 252 water components so the component array upgrades from
Uint8Array to Uint16Array. Ensure the test asserts termination and correct
water-only traversal, since this change touches src/core/ and must be covered by
tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 346ef8d2-f1b7-47fb-b7f6-ce90f7c1c293
📒 Files selected for processing (1)
src/core/pathfinding/algorithms/AStar.WaterHierarchical.ts
| tile, | ||
| maxDistance, | ||
| (t: TileRef) => this.graph.getComponentId(t) !== LAND_MARKER, | ||
| (t: TileRef) => this.map.isWater(t), |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
Add a regression test for the 253+ water-component crash scenario.
No test changes are included with this fix. The repository guideline requires that all changes to src/core/ include tests, and this change fixes a severe production crash (browser tab crash on maps like Indian Subcontinent), so a targeted regression test would guard against reintroducing the sentinel-width bug (e.g., a map fixture forcing ConnectedComponents to promote from Uint8Array to Uint16Array, then asserting findNearestNode/BFS terminates without traversing land).
Do you want me to draft a test case that constructs a map with 253+ water components to exercise this path?
As per path instructions, "All changes to src/core/ must include tests."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/core/pathfinding/algorithms/AStar.WaterHierarchical.ts` at line 316, Add
a regression test for the 253+ water-component crash in AStar.WaterHierarchical
by exercising the ConnectedComponents sentinel-width promotion path and
verifying findNearestNode/BFS completes without crossing land. Use the
AStar.WaterHierarchical and ConnectedComponents symbols to locate the relevant
logic, and add a targeted map fixture or mocked map setup that forces more than
252 water components so the component array upgrades from Uint8Array to
Uint16Array. Ensure the test asserts termination and correct water-only
traversal, since this change touches src/core/ and must be covered by tests.
Source: Path instructions
|
I don't think this fixes the issue, the indian subcontinent only has 15 water components |
Plain JS Array<number> uses ~8 bytes/element in V8 due to boxing. For Indian Subcontinent (2000x2220 = 4.44M tiles), the refToX and refToY lookup tables together consumed ~71 MB per GameMapImpl instance. Since two instances are created at game start (main map + minimap), this was ~142 MB of extra heap pressure on top of the terrain texture, RGBA build buffer, Uint16Array state, and Vite's unminified dev bundle — pushing the Chrome tab past the OS per-process memory limit and triggering an 'Aw, Snap!' OOM kill. Fix: switch refToX and refToY to Uint16Array (2 bytes/element; all map dimensions fit in 0-65535), and yToRef to Int32Array (tile refs on large maps exceed Uint16 range). This saves ~107 MB total across both GameMapImpl instances for Indian Subcontinent, keeping the tab alive. World map (2000x1000 = 2M tiles) was unaffected because its LUTs only needed ~32 MB total — well within budget.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/core/game/GameMap.ts`:
- Around line 112-121: The Uint16Array-backed coordinate tables in GameMap
constructor logic assume x/y always stay within 65535, but this is only
documented and not enforced. Add an explicit invariant check in the GameMap
initialization path (where refToX and refToY are created) to fail fast if map
dimensions or coordinate ranges exceed the Uint16 limit, using the existing
GameMap symbols to locate the code. Also add or update a unit test around this
boundary to verify the guard is enforced and the assumption is locked in.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3b3d1e2b-1f7a-4e8e-ad86-da1aa8ceff64
📒 Files selected for processing (1)
src/core/game/GameMap.ts
There was a problem hiding this comment.
GameMapImpl allocated refToX and refToY as plain Array<number>, costing ~8 bytes/element in V8. On Indian Subcontinent (2000×2220 = 4.44M tiles), two instances at startup consumed ~142 MB just for these LUTs, OOM-killing the tab.
Switched to Uint16Array (coords fit in 0–65535) and Int32Array for yToRef. Saves ~67 MB. tsc --noEmit clean.
This should fully fix it as my original diagnosis did fix a bad code practice (the wrong fix though!). Looking at it though it is ranked 12th in map size. Of course giant world map is first and second being hawaii which is odd. I'm researching this right now...
this change is inherently meaningful if it doesn't break anything. My tests did not show anything breaking but im still trying to figure out why Indian Subcontinent is the specific one that broke
TLDR
This fixes a genuine memory inefficiency. Whether it fully resolves the reported crash or additional factors (high nation count, new custom flags) are also contributing is worth verifying after merge.
Resolves #4401
Description:
Fixes a critical browser tab crash ("Aw, Snap! Something went wrong") when loading the game on the new Indian Subcontinent map (or any map with >= 253 water components) in Solo Mode.
Technical Cause:
Solution:
Changed the hardcoded sentinel check to query the map's terrain directly via this.map.isWater(t). This makes the check immune to any component ID promotions or sentinel representation upgrades. Verified that the existing water pathfinding test suite passes successfully.
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
blontd6