Skip to content

Handle all out-of-range radarcol indexes in RadarMap - #88

Merged
kaczy93 merged 1 commit into
kaczy93:masterfrom
DavideRei:fix-radarmap-edge-cases
Nov 23, 2026
Merged

kaczy93 merged 1 commit into
kaczy93:masterfrom
DavideRei:fix-radarmap-edge-cases

Conversation

@DavideRei

@DavideRei DavideRei commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Three more ways for RadarMap to read past radarcol or pick the wrong color:

  • The constructor reads _radarColors[landTile.Id] with no check, so a land id past the end of radarcol throws at startup.
  • The fallback index 0x4000 is itself out of range when radarcol has 0x4000 entries or fewer, so the fallback throws too.
  • UpdateRadar computes (ushort)(topStaticTile.Id + 0x4000). Static ids of 0xC000 and above wrap onto land colors, so after an edit the radar shows a land color, while at startup the same tile gets its own color (or the fallback).

Fix

  • One GetColor(int radarId, x, y) helper used by the constructor and Update: out-of-range indexes are logged and get the 0x4000 color, or 0 if radarcol has no static colors.
  • The radar index is an int from UpdateRadar to RadarMap.Update, so it no longer wraps.

The startup log line now gives the radarcol index (No radar color for index 0x8000 at block 0,0) instead of "Invalid static tile", because a bad land id can also land there.

Testing

  • Synthetic map/statics/radarcol files loaded through ServerLandscape, then UpdateRadar, compared before and after: land id past the end, radarcol of 0x3000 and 0x4000 entries, static 0xC000/0xFFFF with radarcol of 0x8000, 0x10000 and 0x14000 entries. No exceptions, startup and update now agree, valid ids keep their color.
  • Solution builds; Shared.Tests and CentrED.Tests pass.

🤖 Generated with Claude Code

Look up every radar color through one GetColor helper, which logs and
falls back to the 0x4000 color, or to 0 when radarcol has no static
entries at all. This covers:

- Land tile ids past the end of radarcol, which were not checked at
  startup and threw.
- radarcol files with 0x4000 entries or fewer, where the 0x4000
  fallback was itself out of range.
- Static ids of 0xC000 and above in UpdateRadar: `(ushort)(Id + 0x4000)`
  wrapped them onto land colors, so the radar showed a different color
  after an edit than at startup. The radar index is now an int.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@DavideRei
DavideRei force-pushed the fix-radarmap-edge-cases branch from f67d336 to 654d4e8 Compare November 23, 2026 08:38
@kaczy93
kaczy93 merged commit 3860116 into kaczy93:master Nov 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants