Skip to content

LostFocus crash #1

Description

@maximilien-noal

** Issue **

when clicking on edit... to edit an existing breakpoint:

Unhandled exception. System.Reflection.AmbiguousMatchException: Ambiguous match found for 'Avalonia.Input.FocusManager Avalonia.Input.IInputElement GetFocusedElement()'.
at System.RuntimeType.GetMethodImpl(String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
at System.Type.GetMethod(String name, BindingFlags bindingAttr)
at Avalonia.Controls.Utils.AvaloniaInternalCompatibilityHelper.GetFocusedElement(InputElement inputElement)
at Avalonia.Controls.DataGrid.DataGrid_LostFocus(Object sender, RoutedEventArgs e)
at Avalonia.Interactivity.EventRoute.RaiseEventImpl(RoutedEventArgs e)
at Avalonia.Interactivity.EventRoute.RaiseEvent(Interactive source, RoutedEventArgs e)
at Avalonia.Interactivity.Interactive.RaiseEvent(RoutedEventArgs e)
at Avalonia.Input.KeyboardDevice.SetFocusedElement(IInputElement element, NavigationMethod method, KeyModifiers keyModifiers, Boolean isFocusChangeCancellable)
at Avalonia.Input.FocusManager.Focus(IInputElement element, NavigationMethod method, KeyModifiers keyModifiers)
at Avalonia.Input.InputElement.Focus(NavigationMethod method, KeyModifiers keyModifiers)
at Avalonia.Input.FocusManager.OnPreviewPointerEventHandler(Object sender, RoutedEventArgs e)
at Avalonia.Reactive.LightweightObservableBase1.PublishNext(T value) at Avalonia.Interactivity.EventRoute.RaiseEventImpl(RoutedEventArgs e) at Avalonia.Interactivity.EventRoute.RaiseEvent(Interactive source, RoutedEventArgs e) at Avalonia.Interactivity.Interactive.RaiseEvent(RoutedEventArgs e) at Avalonia.Input.MouseDevice.MouseDown(IMouseDevice device, UInt64 timestamp, IInputRoot root, Point p, PointerPointProperties properties, KeyModifiers inputModifiers, IInputElement hitTest) at Avalonia.Input.MouseDevice.ProcessRawEvent(RawPointerEventArgs e) at Avalonia.Threading.Dispatcher.Send(SendOrPostCallback action, Object arg, Nullable1 priority)
at Avalonia.Controls.PresentationSource.HandleInput(RawInputEventArgs e)
at Avalonia.Win32.WindowImpl.AppWndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
at Avalonia.Win32.WindowImpl.WndProcMessageHandler(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
at Avalonia.Win32.Interop.UnmanagedMethods.DispatchMessage(MSG& lpmsg)
at Avalonia.Win32.Win32DispatcherImpl.RunLoop(CancellationToken cancellationToken)
at Avalonia.Threading.DispatcherFrame.Run(IControlledDispatcherImpl impl)
at Avalonia.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken)
at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.StartCore(String[] args)
at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args)
at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder builder, String[] args, ShutdownMode shutdownMode)
at Spice86.Program.Main(String[] args) in C:\Users\noalm\source\repos\Spice86\src\Spice86\Program.cs:line 53

C:\Users\noalm\source\repos\Spice86\src\Spice86\bin\Release\net10.0\Spice86.exe (process 49280) exited with code -532462766 (0xe0434352).
Press any key to close this

** What to avoid **

A workaround in the client application:

Fixed in OpenRakis/Spice86@0af9b33.

The crash is in Spice86.DataGrid 0.1.0: its DataGrid_LostFocus class handler calls AvaloniaInternalCompatibilityHelper.GetFocusedElement, which uses Type.GetMethod("GetFocusedElement", ...) and now matches multiple Avalonia 12 overloads -> AmbiguousMatchException. Clicking Edit... moved focus off the data grid and tripped that path.

Workaround: the toolbar buttons (New..., Edit..., Remove, Remove All, Disable all, Enable all, Toggle) are now Focusable="False", so clicking them no longer steals focus from the grid and the buggy LostFocus handler never runs. Click handling is unaffected. Proper fix belongs upstream in the Spice86.DataGrid package.

dotnet build: 0 warnings/0 errors. dotnet test (UI): 51 passed.

see: OpenRakis/Spice86#2164

** Approach **

  • Use AvaloniaFact and UI TDD (red test, passing test)

** Afterwards **

New nuget release

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions