Prototype icon indicating copy to clipboard operation
Prototype copied to clipboard

Adding a new `TileDirection.INVALID` value causes existing code to crash

Open pcen opened this issue 2 years ago • 3 comments

I attempted to add TileDirection.INVALID, and without changing any other code, the game crashes with the following error when trying to move a unit to a new tile:

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'Invalid TileDirection')
   at C7GameData.Tile.HasRiverCrossing(TileDirection dir)

This is strange because I did not reference the INVALID enum anywhere in code other than adding it to the enum declaration.

pcen avatar Feb 14 '23 23:02 pcen

I imagine some code is iterating over the enum values and calling HasRiverCrossing for each. It's probably a good idea for most enums to have a default or invalid value though.

WildWeazel avatar Mar 07 '23 05:03 WildWeazel

Looks like it's GameMap's computeNeighbors. Should be easy to add a check if you want to add an Invalid TileDirection

benskywalker avatar Sep 23 '23 02:09 benskywalker

Good find. I wonder if there's a common pattern to deal with this kind of thing.

WildWeazel avatar Oct 12 '23 22:10 WildWeazel