Change: recover when possible from crashes during a crash #11238
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.
Motivation / Problem
When, for example, creating of a savegame fails during the crash handler, everything stops and the user is presented with what-ever the OS decides. But in most cases, we don't actually mind that much that the savegame or, for example, the screenshot failed to be created. These issues should just be ignored and the crashlog should do as much as possible.
Description
By clever use of
setjmp
and Windows SEH, we can protect certain blocks, that if they cause a segfault or something, we capture that, clean it up, and return in the crashlog process.I went with the function name
TryExecute
, which takes astd::function
that should return a boolean. The function itself should also return a boolean. Now the rules are simple:If the function returns true and caused no problem,
TryExecute
returns true.If the function returns false and caused no problem,
TryExecute
returns false (indicating that the function failed).If the function caused an exception,
TryExecute
returns false (indicating that the function failed).This way, if the
TryExecute
return true, it means everything was fine. This allows for the caller to handle what he wants to be done with problems.This solution is heavily inspired by the work of @JGRennison in JGRPP; the main difference is that there a
char *
is returned, and there is a checkpoint system to ensure it is reset to a known-good-state if an exception happens. Here however I made it a bit more generic that I could also attachWriteSavegame
to it, and leave the handling of the buffer to the caller. Otherwise, the implementation and idea behind it is very similar, although I did clean up some things, named things slightly different, etc, to hopefully pass easier in our review process.Limitations
I did not invest time in adding this functionality to
FillCrashLog
, because with #11232 that is going to change significantly enough that it was not worth my time and effort. In other words: I couldn't find a simple way to remember and restore aback_insert_iterator
, which made that change blow up in my face. So postponing till #11232 :) This PR was mostly to prevent issues with savegames anyway (as #11236 took that away from the Windows users).Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.