You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix crash when more than 2^24 terrain tiles are edited - #6424
GameMapImpl recorded every tile whose terrain changed in a Map, which holds at most 2^24 (~16.7M) entries. World10000 has 50M tiles, and with water nukes each large crater adds roughly 32k tiles to the log, so a long game passed the limit and crashed with RangeError: Map maximum size exceeded.
The log now uses a one-bit-per-tile mask plus growable typed arrays, so it has no entry limit. First-edit order and the snapshot format are unchanged. GameImpl.addViewResync built a Set from the same log and would have hit the same limit, so it now calls a new isTerrainEdited on the map.
Tests: tests/core/game/GameMap.terrainEdits.test.ts covers edit order, original bytes, snapshot and restore round-trip, and a map with more than 2^24 edited tiles. That last test fails on main with the same RangeError and passes with this change. On my machine, npm test also fails 4 client tests (InventoryModal, PlayerName, WinModalProvisionalXp, and a WebGL perf test); they fail the same way on main without this change.
Please complete the following:
I have added screenshots for all UI updates (no UI changes)
I process any text displayed to the user through translateText() and I've added it to the en.json file (no new text)
GameMapImpl logged every tile whose terrain changed in a Map, which holds
at most 2^24 entries. World10000 has 50M tiles, so a long water-nuke game
there ran past the limit and crashed with "Map maximum size exceeded".
Keep the log in a one-bit-per-tile mask plus growable typed arrays, which
have no entry limit. The snapshot format and first-edit order are
unchanged. addViewResync built a Set from the same log and would have hit
the same limit; it now asks the map through isTerrainEdited.
Resolvesopenfrontio#6388
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You have signed the CLA already but the status is still pending? Let us recheck it.
Review was skipped as selected files did not have any reviewable changes.
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 3a575c38-3bb5-4ef4-872e-17c44ce0ec23
Commits
Reviewing files that changed from the base of the PR and between 19006cb and 3fbacab.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
GameMapImpl now tracks terrain edits with a bitset and typed arrays. Hash calculation and snapshots use these records, and snapshot restoration applies an updated fresh-map check. GameImpl.addViewResync checks edit status per tile. Tests cover edit order, snapshot restoration, and more than 2^24 edited tiles.
Changes
Terrain edit tracking
Layer / File(s)
Summary
Record terrain edits packages/engine-lib/src/game/GameMapImpl.ts, packages/engine/src/game/GameImpl.ts, tests/core/game/GameMap.terrainEdits.test.ts
GameMapImpl records each edited tile once, in first-edit order, using a bitset and dynamically grown typed arrays. GameImpl.addViewResync checks each tile with isTerrainEdited. Tests cover edit order and tracking more than 2^24 tiles.
Build and restore snapshots packages/engine-lib/src/game/GameMapImpl.ts, tests/core/game/GameMap.terrainEdits.test.ts
Pristine-hash calculation and snapshots use the typed-array edit records. Snapshot restoration rejects a map with an allocated edit bitset or nonzero state. Tests verify restored terrain and pristine hash.
This change removes the crash when more than 2^24 terrain tiles are edited, while keeping edit order and the snapshot format. No code risk was found. A reviewer still needs to assign a milestone to clear the failing process check.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: a crash fix for edited terrain tiles exceeding the 2^24 Map entry limit. The changeset replaces the Map-based edit log in GameMapImpl with a bitset and typed arrays, w…
Description check
The description explains the crash cause (Map limit of 2^24 entries on World10000 with water nukes), the bitset and typed-array fix, the GameImpl.addViewResync change, and the new tests. It relates di…
Linked Issues check
Issue #6388 requires that the game keep running after more than 2^24 terrain tiles are edited. The reported crash comes from the Map used as the edit log in GameMapImpl (pristineTerrain). The di…
Out of Scope Changes check
All changed code maps to issue #6388. The edit log change in GameMapImpl.ts removes the crash. The addViewResync change in GameImpl.ts removes the same limit on the second consumer named in the …
Full details: Title check
Explanation
The title names the main change: a crash fix for edited terrain tiles exceeding the 2^24 Map entry limit. The changeset replaces the Map-based edit log in GameMapImpl with a bitset and typed arrays, which matches the title.
Full details: Description check
Explanation
The description explains the crash cause (Map limit of 2^24 entries on World10000 with water nukes), the bitset and typed-array fix, the GameImpl.addViewResync change, and the new tests. It relates directly to the changeset.
Full details: Linked Issues check
Explanation
Issue #6388 requires that the game keep running after more than 2^24 terrain tiles are edited. The reported crash comes from the Map used as the edit log in GameMapImpl (pristineTerrain). The diff to packages/engine-lib/src/game/GameMapImpl.ts replaces that Map with a one-bit-per-tile editedMask (Uint8Array of (terrain.length + 7) >>> 3 bytes) and growable typed arrays editTiles (Uint32Array) and editOriginal (Uint8Array). noteTerrainEdit records each tile once, in first-edit order, and grows capacity up to terrain.length. No entry-count limit remains. The issue also names GameImpl.addViewResync, which built a Set from the same log. The diff to packages/engine/src/game/GameImpl.ts now calls map.isTerrainEdited(tile), which reads the mask. Pristine-hash, snapshot, and restore paths read the new arrays. The snapshot field layout is unchanged. The restore guard now checks editedMask, and the other validations remain. The summary reports a new test file, tests/core/game/GameMap.terrainEdits.test.ts, with a case above 2^24 edited tiles. I did not inspect that test file. The test result is taken from the PR description and summary, not from a run. No non-coding requirements exist in the issue.
Full details: Out of Scope Changes check
Explanation
All changed code maps to issue #6388. The edit log change in GameMapImpl.ts removes the crash. The addViewResync change in GameImpl.ts removes the same limit on the second consumer named in the issue. The editedTerrainTiles() return type changes from TileRef[] to Uint32Array, which follows from the new storage and is needed by the fix. The new test file covers the changed behavior. I did not find a change unrelated to the issue in the reviewed diffs. I did not check other callers of editedTerrainTiles() for a return-type dependency. The PR description reports four client test failures that also occur on main. These come from no code change in this PR.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
A tile is marked, its first edit kept, In typed arrays, the records rest. Snapshots hold the bytes in view, Hashes use the originals too. Beyond the old limit, tracking grew.
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: b0ef967c-4f5a-46e6-bda0-59ded44a17cb
Commits
Reviewing files that changed from the base of the PR and between a084d23 and dff8b72.
Files selected for processing: 3
packages/engine-lib/src/game/GameMapImpl.ts
packages/engine/src/game/GameImpl.ts
tests/core/game/GameMap.terrainEdits.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
Verdict: No issues found. Checked for bugs and CLAUDE.md compliance. (0 critical, 0 major, 0 minor)
The only new commit, 19006cb, merges main into the branch. It brings in the PR-readiness workflow, a CONTRIBUTING.md change and the new map-category removals from #6422. None of these hunks touch this PR's files (GameMapImpl.ts, GameImpl.ts, GameMap.terrainEdits.test.ts). The merge doesn't change terrain data, map dimensions or anything the terrain-edit log depends on, so it doesn't affect the fix.
Reviewed range: 19006cb..3fbacab (incremental since the previous Claude review).
Verdict: No issues found. Checked for bugs and CLAUDE.md compliance. (0 critical, 0 major, 0 minor)
The only commit in this range is a merge of main into the branch. It brings in the Canada map data fix (#6430) and the desktop/Google sign-in client changes (AccountModal.ts, Auth.ts, DesktopShell.ts, en.json, plus their tests). It touches none of this PR's files (GameMapImpl.ts, GameImpl.ts, GameMap.terrainEdits.test.ts), and none of the merged changes affect the terrain-edit log or isTerrainEdited. The PR's test builds its own map and doesn't load any map data, so the new Canada binaries can't change its result.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #6388
Description:
GameMapImplrecorded every tile whose terrain changed in aMap, which holds at most 2^24 (~16.7M) entries. World10000 has 50M tiles, and with water nukes each large crater adds roughly 32k tiles to the log, so a long game passed the limit and crashed withRangeError: Map maximum size exceeded.The log now uses a one-bit-per-tile mask plus growable typed arrays, so it has no entry limit. First-edit order and the snapshot format are unchanged.
GameImpl.addViewResyncbuilt aSetfrom the same log and would have hit the same limit, so it now calls a newisTerrainEditedon the map.Tests:
tests/core/game/GameMap.terrainEdits.test.tscovers edit order, original bytes, snapshot and restore round-trip, and a map with more than 2^24 edited tiles. That last test fails onmainwith the sameRangeErrorand passes with this change. On my machine,npm testalso fails 4 client tests (InventoryModal,PlayerName,WinModalProvisionalXp, and a WebGL perf test); they fail the same way onmainwithout this change.Please complete the following:
DIscord username
theziz_