Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pcen opened this issue Feb 14, 2023 · 3 comments
Open

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

pcen opened this issue Feb 14, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@pcen
Copy link
Contributor

pcen commented Feb 14, 2023

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 pcen added the bug Something isn't working label Feb 14, 2023
@WildWeazel
Copy link
Member

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
Copy link
Contributor

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

@WildWeazel
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants