Fix #9463: [Win32] Try to work around XAudio2 crashes by catching SEH exceptions. #9549
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
While it looks like the XAudio2 crashes reported e.g. in #9463 are caused by third-party components, users will still blame OpenTTD at first. As such, if we can do something, user experience is improved, especially as other audio drivers besides XAudio2 are available.
Description
The provided crash logs point to an illegal access exception during XAudio2 creation. Windows reports such errors using the SEH mechanism which can be caught by platform-specific code. If a SEH exception is encountered, just fail driver creation and let the system do the normal fallback.
The extra function is needed as SEH handling can't be used in contexts that rely on C++ unwinding.
Limitations
As I don't have the suspected third-party software components, I can't verify if this PR actually fixes the reported issues.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.