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

Prevent corrupting last loaded submap. Thanks to wito for finding it. #2381

Merged
merged 1 commit into from Aug 13, 2013

Conversation

kevingranade
Copy link
Member

May fix #426 fix #437 and fix #1341.
To reproduce previous issue:
Clear maps, make a new character, immediately save, exit program, restart, and load.
The submap approximately 48 squares SE of the shelter will be completely uniform and featureless.
Also if you backup the save/maps.txt file after saving, then load and save. Comparing the backup and new file will show that the last listed submap is a uniform terrain type, and has no features, even if the previous version of it did.

Big props to wito, he pointed out that there was something funny happening with the last submap in maps.txt, and that the value used was the previous value of tmpter, both of which were instrumental in figuring out what was going wrong.

Post-mortem:
What was happening was that after processing the last submap from maps.txt, the program would check for EOF and not find it, because there was a single newline left. It would then try to read a submap, but every single read would fail. Since none of the variables in the loop were initialized (boo), they would retain their values from the previous iteration, so the x,y,z, turns, etc would match the last submap, the terrain would be the last terrain* read (SE corner of submap), and the radiation level would be the same as the last one read. The submap would be featureless, because the last string_identifier read was "---", which would cause it to exit from feature processing, at which point it would re-write the most recently written submap with a garbage version of itself. The error would then be persisted the next time the map was written to disk.

The fix is simple, check for EOF after trying to read past the end of the current submap and exit the loop if it's encountered.

*On debug builds, it uses the last terrain read, on release builds it gets a 0, which I suspect is the value of radtmp. Other contents of the submap may have caused the LOS-blocking, crash-causing version that has also been reported.

@CataJenkins
Copy link

Build successful!
Refer to this link for build results: http://ci.narc.ro/job/Cataclysm-PullRequests/285/

@fergus-dall
Copy link
Contributor

Definitely doesn't fix #1341, that seems to be a problem with overmap boarders.

i2amroy added a commit that referenced this pull request Aug 13, 2013
@i2amroy i2amroy merged commit 39d7985 into CleverRaven:master Aug 13, 2013
@kevingranade kevingranade deleted the fix-nothing branch April 26, 2014 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants