Core/State: Refactor logic for determining the relative age of existing savestates. #12262
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.
Plus another minor robustness issue I ran into while testing. Turns out
localtime()
can return a nullptr, andwcsftime()
asserts if you pass it one.I noticed this back when reviewing #12217. The code previously did this indirectly via
std::map<double, int>
, the key being the timestamp, which required a questionable workaround for the case where multiple states have the same timestamp. By having a particular combination of timestamps in the on-disk savestates, you could cause this workaround to infinitely loop, locking up Dolphin. This avoids this completely by refactoring the logic and just usingstd::vector
instead.Admittedly, this is pretty difficult to trigger by accident, but if you just manually edit two states to have eg. 1e300 as the timestamp this triggers, because incrementing a double of such magnitude by 0.001 just results in the same double again.