NullReferenceException when drawing in InkCanvas after editing mode change
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
* .NET Core Version: `5.0.100-preview.5.20279.10`
* Windows version: `20262.1.amd64fre.fe_release.201113-1436`
* Does the bug reproduce also in WPF for .NET Framework 4.8?: `Yes`
**Problem description:** When `InkCanvas.EditingMode` is changed to `Select` after drawing a stroke and then back to `Ink`, a `NullReferenceException` is thrown on mouse down and the application crashes.
**Actual behavior:**
```
PresentationFramework.dll!MS.Internal.Ink.InkCollectionBehavior.StylusInputContinue(System.Windows.Input.StylusPointCollection stylusPoints, bool userInitiated) PresentationFramework.dll!MS.Internal.Ink.StylusEditingBehavior.MS.Internal.Ink.IStylusEditing.AddStylusPoints(System.Windows.Input.StylusPointCollection stylusPoints, bool userInitiated)
PresentationFramework.dll!MS.Internal.Ink.EditingCoordinator.InitializeCapture(System.Windows.Input.InputDevice inputDevice, MS.Internal.Ink.IStylusEditing stylusEditingBehavior, bool userInitiated, bool resetDynamicRenderer)
PresentationFramework.dll!MS.Internal.Ink.EditingCoordinator.OnInkCanvasDeviceDown(object sender, System.Windows.Input.InputEventArgs args)
PresentationFramework.dll!System.Windows.Controls.InkCanvas._OnDeviceDown(object sender, System.__Canon e)
PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget)
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {MS.Internal.Controls.InkCanvasSelectionAdorner}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, bool reRaised = false)
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {MS.Internal.Controls.InkCanvasSelectionAdorner}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs})
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs})
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea()
PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input)
PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport)
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel)
PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd = 0x00000000001308c6, MS.Internal.Interop.WindowMessage msg = WM_LBUTTONDOWN, System.IntPtr wParam = 0x0000000000000001, System.IntPtr lParam = 0x000000000124013a, ref bool handled = false)
PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd = 0x00000000001308c6, int msg, System.IntPtr wParam = 0x0000000000000001, System.IntPtr lParam = 0x000000000124013a, ref bool handled = false)
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 0x00000000001308c6, int msg, System.IntPtr wParam = 0x0000000000000001, System.IntPtr lParam = 0x000000000124013a, ref bool handled = false)
```
**Expected behavior:** No crash. Changing the `EditMode` to `Select` actually results in lasso selection mode rather than the selection adorner mode (with the stroke as current lasso path) which I find rather suspicious and potentially undesirable, unless there is a reason to support changing modes while inking, but then the existing geometry should either change from ink to lasso or it should keep the ink and start a new lasso path.
**Minimal repro:**
```xml
```
```c#
private void OnStrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e)
{
_canvas.EditingMode = InkCanvasEditingMode.Select;
}
private void OnInkClick(object sender, RoutedEventArgs e)
{
_canvas.EditingMode = InkCanvasEditingMode.Ink;
}
```
1. Draw (I am using mouse) on the canvas, upon finishing the stroke the canvas should change to selection mode
2. Click the button to change the canvas back to inking mode
3. Draw again - crash on mouse down
Contributor guide
Assessment
This issue has not been assessed yet.