Fix AccessViolation on grouped ListViewBase with Drag+Drop #9119 #9932
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.
This PR should fix the AccessViolation that happens when using DragDrop on grouped ListView or GridView, see Issue #9119.
Description
As can be seen from the strack trace of the crashes, the error comes from CInputServices::InitializeDirectManipulationViewportValues. This method has a parameter pDirectManipulationService which is marked as optional. It is called with a NULL parameter in case of beginning of mouse edge scrolling here:
microsoft-ui-xaml/src/dxaml/xcp/core/input/InputServices.cpp
Line 9306 in aeed4c1
There are multiple places where pDirectManipulationService is accessed inside InitializeDirectManipulationViewportValues, each time with a check against null. But in case of clip content, there is no check. Looks like grouping will result in clip content being used, and this in turn will lead to the AccessViolation when the framework tries to begin an edge scroll animation (where NULL is passed for pDirectManipulationService). There is no other place in this method where unchecked parameters are accessed, so I am very confident that this is the exact place where the AccessViolation occurs.
Like in all other places where pDirectManipulationService is checked against null, the provided translations from the method parameters are used as a replacement, when the pDirectManipulationService is not available. See similar calls here:
microsoft-ui-xaml/src/dxaml/xcp/core/input/InputServices.cpp
Line 6523 in aeed4c1
Or here:
microsoft-ui-xaml/src/dxaml/xcp/core/input/InputServices.cpp
Line 6571 in aeed4c1
Motivation and Context
Both Drag+Drop and Grouping are critical core features. Both can be used easily together in all XAML platforms except for WinUI 3. This PR aims to make it possible to use these important features together in WinUI 3 as well.
How Has This Been Tested?
Since Microsoft has not yet made public all build dependencies, I could not fully test this myself. But the access violation definitely comes from this method, and this is the only place in the method where an unchecked access to an optional parameter happens. A simpe repro is available in the linked issue.