Skip to content

SurfaceLoader fails in WinUI because of unsupported API usage #316

@Marv51

Description

@Marv51

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().

var displayInformation = DisplayInformation.GetForCurrentView();
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

// 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
  • 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)
  • Windows 11 21H2 (Build 22000)
  • Other (specify)

Other Windows Build number

No response

App minimum and target SDK version

  • 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)
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcomponents::mediaCreate animated Media effects on UI elements

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions