macOS: Prevent crash with popups #17218
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.
What does the pull request do?
Avalonia started crashing on certain versions of macOS after #16365 when showing popups. This is strange because that PR doesn't actually change anything to do with popups. After debugging the issue on macOS 12 (I couldn't get it to repro with any more recent versions of macOS) I discovered that it was due to this field not being initialized.
I've tried to make xcode detect places where we don't zero-initialize C++ fields to prevent this problem in other places, but I've failed to do so. Passing
-Wmissing-field-initializers
has no effect and xcode's C++ analyzer doesn't catch this problem either.Given that this seems to be a problem that C++ can't warn for, I'm opening a PR with this fix and we'll keep our fingers crossed that we have remembered to initialize all other fields, and will remember to do so in future. If there's anyone out there who's better at C++ on macOS than me and who can manage to get it producing a warning for uninitialized fields: a PR would be appreciated.
Fixed issues
Fixes #17018