Port stylus shutdown fix from 4.8 #4983
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.
Addresses Issue #4982. This is a port from a servicing fix in .NET 4.7-4.8.
Description
HwndSource shuts down its stylus stack when it receives WM_DESTROY. In the repro it doesn't receive WM_DESTROY, and therefore leaks many resources associated with stylus/touch including the HwndSource object itself, but most notably the handles used for communication with WISP.
More precisely, the logic for WM_DESTROY lives in the PublicHooks message filter, which is only called if public hooks have been added to the HwndSource. All the places where WPF itself creates the HwndSource add hooks - the chief examples are Window and Popup - so "normal" apps don't leak. But the repro creates HwndSource directly and doesn't add hooks, hence it leaks.
Fixed by adding WM_DESTROY logic to the Input message filter, which is always called (unless a public hook handles the WM_DESTROY message).
Customer Impact
App eventually crashes when it runs out of handles.
Regression
Introduced in 4.7.
Testing
Ad-hoc around customer scenario.
Standard regression testing
Risk
Low. Port of a .NETFx servicing fix released earlier this year.