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

System.NullReferenceException in Avalonia.Controls.Utils.KeyboardHelper #16199

Open
scottdoingwork opened this issue Jul 2, 2024 · 3 comments

Comments

@scottdoingwork
Copy link

Describe the bug

var keymap = TopLevel.GetTopLevel(target)!.PlatformSettings!.HotkeyConfiguration;
TopLevel.GetTopLevel(target) returns null, causing program crash.

System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Avalonia.Controls.DataGrid
StackTrace:
at Avalonia.Controls.Utils.KeyboardHelper.GetPlatformCtrlOrCmdKeyModifier(Control target) in Avalonia.Controls.Utils\KeyboardHelper.cs:line 22
......
at Avalonia.Win32.WindowImpl in src\Windows\Avalonia.Win32\WindowImpl.AppWndProc.cs 769

To Reproduce

Put DataGrid in a popup. Pressing mouse left button on datagrid let popup close immediately.

Expected behavior

Program won't crash in this situation.

Avalonia version

11.0.11

OS

Windows

Additional context

No response

@MidnightEmpire
Copy link

Same issue... Maybe exist some workaround?

@timunie
Copy link
Contributor

timunie commented Jul 4, 2024

Best "workaround" would be to clone the source, try to solve the issue and file a PR.

@maxkatz6
Copy link
Member

maxkatz6 commented Jul 4, 2024

Yeah, it should be easy to add a null check.
Not necessary the best solution there, as PlatformSettings should not be null for popups.

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

No branches or pull requests

4 participants