Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mica] Fix crash accessing BaseWindowHandler::m_capabilities from Capabilities::Changed handler #6288

Merged
merged 3 commits into from
Nov 15, 2021

Conversation

DmitriyKomin
Copy link
Contributor

BaseWindowHandler (owned by MicaController) subscribes to Windows::UI::Composition::CompositionCapabilities::Changed event. The current Changed handler captures 'this' by reference and tries to access this->m_capabilities. It's possible the handler is invoked after BaseWindowHandler is already cleaned up and access via this is invalid. To fix, capture this as a weak_ptr and resolve it before accessing class members in the handler.

Originally BaseWindowHandler was a simple C++ struct; make it derive from winrt::implements<..., IInspectable> to support ref counting and strong/weak refs.

The same problematic pattern was used for UISettings::AdvancedEffectsEnabledChanged and PowerManager::EnergySaverStatusChanged, so apply the fix there as well.

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Nov 12, 2021
@DmitriyKomin DmitriyKomin self-assigned this Nov 12, 2021
Copy link
Contributor

@codendone codendone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@ranjeshj
Copy link
Contributor

/azp run

@ranjeshj ranjeshj added area-Materials Reveal, Acrylic, lighting, etc. team-Rendering Issue for the Rendering team and removed needs-triage Issue needs to be triaged by the area owners labels Nov 14, 2021
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@DmitriyKomin DmitriyKomin merged commit f904131 into main Nov 15, 2021
@DmitriyKomin DmitriyKomin deleted the user/dkomin/systembackdrop_lambda_crash branch November 15, 2021 22:11
kmahone pushed a commit that referenced this pull request Dec 15, 2021
…abilities::Changed handler (#6288)

* use weak refs to avoid crashes accessing captured data

* remove unnecessary weak refs

* clean up commented code

Co-authored-by: Dmitriy Komin <dkomin@windows.microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Materials Reveal, Acrylic, lighting, etc. team-Rendering Issue for the Rendering team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants