CommunityToolkit / CommunityToolkit/Windows

SurfaceLoader fails in WinUI because of unsupported API usage

Offen
#316 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug components::media
Vorherrschende Sprache
C#
Sterne
1.1k
Forks
166
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

### Describe the bug

In the latest Toolkit from Jan 24 (8.0.240109), SurfaceLoader fails to create a brush, and it will always return `null` on WinUI 3.

This is because the private `SurfaceLoader.LoadSurfaceBrushAsync` method unconditionally calls `DisplayInformation.GetForCurrentView()`. https://github.com/CommunityToolkit/Windows/blob/2735c8718984daa2ddee7a5aa9235f57bead0df7/components/Media/src/Helpers/SurfaceLoader.cs#L103 This is not supported on WinUI 3 and throws a COMException. This exception gets handled, but an empty/null brush will always be returned.

### Steps to reproduce

```csharp
// The Uri does not matter, it throws before loading anything.
_ = await SurfaceLoader.LoadImageAsync(new Uri("https://example.com"), CommunityToolkit.WinUI.Media.DpiMode.DisplayDpiWith96AsLowerBound);

// The exception is handled so it will return `null`.
```

### Expected behavior

No exception is expected.

The old-7.1 winUI branch worked for me. On that branch this dpi issue was commented out:

https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/080bdb99e6810eb2157ad635f00e64a64acabb50/CommunityToolkit.WinUI.UI.Media/Helpers/SurfaceLoader.cs#L99

### Screenshots

_No response_

### Code Platform

- [ ] UWP
- [X] WinAppSDK / WinUI 3
- [ ] Web Assembly (WASM)
- [ ] Android
- [ ] iOS
- [ ] MacOS
- [ ] Linux / GTK

### Windows Build Number

- [ ] Windows 10 1809 (Build 17763)
- [ ] Windows 10 1903 (Build 18362)
- [ ] Windows 10 1909 (Build 18363)
- [ ] Windows 10 2004 (Build 19041)
- [ ] Windows 10 20H2 (Build 19042)
- [ ] Windows 10 21H1 (Build 19043)
- [ ] Windows 10 21H2 (Build 19044)
- [ ] Windows 10 22H2 (Build 19045)
- [X] Windows 11 21H2 (Build 22000)
- [ ] Other (specify)

### Other Windows Build number

_No response_

### App minimum and target SDK version

- [X] Windows 10, version 1809 (Build 17763)
- [ ] Windows 10, version 1903 (Build 18362)
- [ ] Windows 10, version 1909 (Build 18363)
- [ ] Windows 10, version 2004 (Build 19041)
- [ ] Windows 10, version 2104 (Build 20348)
- [X] Windows 11, version 22H2 (Build 22000)
- [ ] Other (specify)

### Other SDK version

_No response_

### Visual Studio Version

2022

### Visual Studio Build Number

_No response_

### Device form factor

_No response_

### Additional context

It might be tempting to think that this is the same issue as #233, however it is not. This is about 10 lines further into SurfaceLoader and this wasn't fixed by #299 in the latest update.

### Help us help you

No, I'm unable to contribute a solution.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne in components/Media/src/Helpers/SurfaceLoader.cs bei LoadSurfaceBrushAsync und vergleiche die aktuelle DPI-Suche mit der verlinkten 7.1 WinUI-Implementierung. Reproduziere das Problem mit SurfaceLoader.LoadImageAsync unter WinUI 3 und überprüfe anschließend, dass der Aufruf für die angegebene URI keinen Null-Pinsel mehr zurückgibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
desktop
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.