Set new_game before loading JSON data #71806
Merged
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.
Summary
None
Purpose of change
While loading core data, we do some adjustments to the (fake) map (yes before the game is started!). But we only set
new_game
after loading the json, but still before we actually start the game. The assumption being that loading json data is just loading json data, it doesn't modify the map or do anything besides moving data around. Well, it does. Camps generate a fake map, perform fake map updates to it, and in the process (about 20 functions down the callstack, in weather_manager::get_temperature) process any items with temperature that those fake updates generated. Since the real map isn't loaded and doesn't exist, it crashes.Describe the solution
Before loading the JSON data, set
new_game
. This prevents the call inweather_manager::get_temperature
and is what I personally would expect to be the case.new_game
is still set to false at the same time(when the game is actually started), so this shouldn't impact gameplay. The only chance for unexpected interactions is if some function explicitly relied onnew_game
being false during loading(?!), which would be a baffling circumstance.There are very few places where
new_game
is checked, so I am pretty confident this is a safe change.Describe alternatives you've considered
I tried changing the default parameters for mapgendata to use a terrain type which wouldn't generate any items, but this wasn't successful. The byproducts of the fake camp update were still being generated. I tried again, using a completely null terrain which couldn't be loaded, same issue.
Testing
All tests besides localization/overmap test passed locally, both before and after the changes. Game compiles, loads, does not crash even with the linked issue's JSON loaded.
Additional context