Initialize datadir_path_value earlier in path_info #61555
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
This seems to correct an edge case that I was running into that would cause
prefix_path
to get initialized to nothing, causing Cataclysm to crash with a segfault whenever I started it outside of the root of the repo. (macOS, CMake, release build, no odd build flags besides that.)Cataclysm ran fine at the root of the git directory as there's the data/ sub-directory there, which is what CDDA would search for as
gfxdir_path_value
would end up being simply "data/" instead of the expected release value of "/usr/local/share/cataclysm-dda/" or similar. The crash itself probably occurs (instead of being caught within main.cpp) because the file exists checks worked fine since it was checkingdatadir_value
, so the game assumedgfxdir_path_value
was safe to use—I'm not to worried about this aspect of the issue, though, since this resolves the crash anyway.Describe the solution
I moved the initialization of
datadir_path_value
to be earlier inPATH_INFO::set_standard_filenames
.Describe alternatives you've considered
None.
Testing
Building and running under CMake works without manually specifying
--datadir
(which uses a different code path to initializedatadir_path_value
, and will end up working as-is)Additional context
This looks like it was introduced as a part of d329307 in #50143, so hopefully @akrieger can take a look at this to make sure this fix is reasonable. I'm fairly certain there aren't any edge cases that I'm unable to check that this change breaks.