Skip to content

Win32: fall back to pixel location when GetPointerDeviceRects is unavailable - #21337

Merged
MrJul merged 2 commits into
AvaloniaUI:masterfrom
Symbai:master
May 15, 2026
Merged

Win32: fall back to pixel location when GetPointerDeviceRects is unavailable#21337
MrJul merged 2 commits into
AvaloniaUI:masterfrom
Symbai:master

Conversation

@Symbai

@Symbai Symbai commented May 10, 2026

Copy link
Copy Markdown
Contributor

What does the pull request do?

Adds a one-time probe for user32.dll!GetPointerDeviceRects and falls back to
POINTER_INFO.ptPixelLocation when the export is missing. This stops Avalonia
from crashing on the first WM_POINTER message under Wine/Proton, where that
WM_POINTER ancillary API has never been implemented.

Fixes #21081.

What is the current behavior?

WindowImpl.GetHimetricLocation (added in #16850) unconditionally P/Invokes
GetPointerDeviceRects to convert ptHimetricLocationRaw into screen pixels.
Wine/Proton's user32.dll does not export this function, so on the first
touch/click the runtime throws:

System.EntryPointNotFoundException: Unable to find an entry point named
'GetPointerDeviceRects' in native library 'user32.dll'.

The exception is fatal in NativeAOT builds (the original report) and in any
configuration where the Win32 message pump's exception isn't being swallowed,
which on Steam Deck means the very first tap on the window's close button
crashes the app.

How was the solution implemented (if it's not obvious)?

The probe uses the same LoadLibrary + GetProcAddress pattern that
Win32Platform.SetDpiAwareness already uses for
SetProcessDpiAwarenessContext i.e., the established Avalonia way of
dealing with optional Win32 entry points without paying for try/catch on a
hot path

@Symbai

Symbai commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

Tests failed with " Warning As Error: Package 'SharpCompress' 0.41.0 has a known moderate severity vulnerability" not related to my changes

@cla-avalonia

cla-avalonia commented May 13, 2026

Copy link
Copy Markdown
Collaborator
  • All contributors have signed the CLA.

@Symbai

Symbai commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

@cla-avalonia agree

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0065387-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@MrJul
MrJul added this pull request to the merge queue May 15, 2026
Merged via the queue into AvaloniaUI:master with commit f47606a May 15, 2026
11 checks passed
@Symbai

Symbai commented May 30, 2026

Copy link
Copy Markdown
Contributor Author

@MrJul Which Avalonia version contains this fix? Because I cannot find it in 12.0.4 changelog.

@timunie

timunie commented May 31, 2026

Copy link
Copy Markdown
Collaborator

The PR has no backport label, so latest nightly and v12.1 should have it.

@Symbai

Symbai commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

Ah, thank you!

@MrJul MrJul added the backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch label Jun 3, 2026
MrJul added a commit to MrJul/Avalonia that referenced this pull request Jun 23, 2026
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
@MrJul MrJul added backported-12.0.x and removed backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'GetPointerDeviceRects' is not available on Proton

5 participants