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

SurfaceLoader.LoadImageAsync always fails in WinUI 3 #233

Closed
4 of 24 tasks
Marv51 opened this issue Sep 11, 2023 · 2 comments · Fixed by #299
Closed
4 of 24 tasks

SurfaceLoader.LoadImageAsync always fails in WinUI 3 #233

Marv51 opened this issue Sep 11, 2023 · 2 comments · Fixed by #299
Labels
bug Something isn't working regression What was working is now broke

Comments

@Marv51
Copy link

Marv51 commented Sep 11, 2023

Describe the bug

I am trying to port my Toolkit 7 usage over to version 8. I am using a PipelineBuilder to create a tiled brush.

This fails currently (was working before) with a NullReferenceException.

I have traced back the origin of that exception to this line in the SurfaceLoader

var compositor = Window.Current.Compositor;

There must be another way to get the Compositor in WinUI 3, because Window.Current is always null in WinUI 3.

Not sure if this is still the preferred approach, but in the old repo, the WinUI branch looks like this:

var compositor = CompositionTarget.GetCompositorForCurrentThread();

https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/a10204e648c372f6a6837c5aa40065761847132e/CommunityToolkit.WinUI.UI.Media/Helpers/SurfaceLoader.cs#L45C13-L45C80

Steps to reproduce

This is a pretty obviously an oversight when porting the UWP code, but here is my code just in case:

Uri _transparentBackground = new Uri("ms-appx:///Images/TransparentBackground.png");

var builder = PipelineBuilder.FromTiles(_transparentBackground, DpiMode.DisplayDpiWith96AsLowerBound);
var brush = builder
            .Shade(Colors.Red, 0.5f)
            .AsBrush();

Expected behavior

No exception expected.

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

No response

Visual Studio Build Number

No response

Device form factor

No response

Additional context

I found a lot of Window.Current.Compositor instances in this part of the code.

Is a #if WINUI3 the preferred approach?

Help us help you

I'd prefer someone else to look at this, so that it can be addressed in a timely manner, because I am not at all familiar with the new tooling.

@michael-hawker michael-hawker added bug Something isn't working regression What was working is now broke labels Sep 19, 2023
@michael-hawker
Copy link
Member

Thanks for the report @Marv51, yeah, this got missed in the port. Not sure how as we were comparing against the winui branch. FYI @Arlodotexe.

@michael-hawker michael-hawker moved this to 🔖 Ready in Toolkit 8.x Sep 19, 2023
@Arlodotexe Arlodotexe moved this from 🔖 Ready to 🆕 New in Toolkit 8.x Nov 7, 2023
@Arlodotexe Arlodotexe moved this from 🆕 New to 🏗 In progress in Toolkit 8.x Nov 7, 2023
@Arlodotexe
Copy link
Member

Possibly related to #235

@Arlodotexe Arlodotexe moved this from 🏗 In progress to 👀 In review in Toolkit 8.x Dec 12, 2023
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Toolkit 8.x Dec 14, 2023
@michael-hawker michael-hawker linked a pull request Dec 14, 2023 that will close this issue
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression What was working is now broke
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants