C7-Game / Prototype

An early-stage, open-source 4X strategy game
https://c7-game.github.io/
MIT License
32 stars 9 forks source link

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

Open pcen opened 1 year ago

pcen commented 1 year ago

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.

WildWeazel commented 1 year ago

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.

benskywalker commented 9 months ago

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

WildWeazel commented 9 months ago

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