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

PipelineVisualFactory BlurEffect crash when run on VM #4855

Open
3 of 14 tasks
kjean667 opened this issue Mar 13, 2023 · 6 comments
Open
3 of 14 tasks

PipelineVisualFactory BlurEffect crash when run on VM #4855

kjean667 opened this issue Mar 13, 2023 · 6 comments
Labels
brush 🖌️ bug 🐛 An unexpected issue that highlights incorrect behavior WinUI 💠 Related to WinUI 3 Version or when paired with External can mean requires fix in WinUI 2/3.

Comments

@kjean667
Copy link

kjean667 commented Mar 13, 2023

Describe the bug

Using PipelineVisualFactory effects in XAML, such as BlurEffect or GrayscaleEffect from the CommunityToolkit.WinUI.UI.Media library, throws an unhandled exception when application is run on a virtual machine (Hyper-V).

This may cause the application to crash.

Regression

Unknown

Reproducible in sample app?

  • This bug can be reproduced in the sample app.

Steps to reproduce

  • In Visual Studio, create a new project using the template "Blank App, Packaged (WinUI 3 in Desktop)".

  • Add the nuget package CommunityToolkit.WinUI.UI.Media to the project.

  • Use the following XAML in MainWindow.xaml:

  xmlns:media="using:CommunityToolkit.WinUI.UI.Media"

  <StackPanel>
    <TextBlock Text="Testing" Margin="10"/>
    <media:UIElementExtensions.VisualFactory>
      <media:PipelineVisualFactory Source="{media:BackdropSource}">
        <media:BlurEffect Amount="2" />
      </media:PipelineVisualFactory>
    </media:UIElementExtensions.VisualFactory>
  </StackPanel>
  • For stack trace of the problem, add the following to the App.xaml.cs and include nuget package System.Diagnostics.EventLog:
    public App()
    {
      UnhandledException += OnUnhandledException;

      this.InitializeComponent();
    }

    private void OnUnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
    {
      EventLog eventLog = new();
      eventLog.Source = "Application Error";
      eventLog.WriteEntry(Package.Current.DisplayName + ": Unhandled exception.\n" + e.Exception, EventLogEntryType.Error);
    }
  • Package the application into an msix and install the package in a Windows installation running in a Hyper-V VM.

  • Start the application.

  • Check the EventLog in Windows, where the exception will be logged under the Program category.

Expected behavior

Either:

  1. The effect shall be made to work even when run on a Hyper-V VM
    or
  2. The exception shall be handled and the effect creation shall be skipped because the hardware does not support it.

The application shall not crash.

Stack trace for the unhandled exception

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.Runtime.InteropServices.COMException (0x80040154): Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))
   at WinRT.BaseActivationFactory..ctor(String typeNamespace, String typeFullName)
   at WinRT.ActivationFactory`1..ctor()
   at System.RuntimeType.CreateInstanceOfT()
   --- End of inner exception stack trace ---
   at System.RuntimeType.CreateInstanceOfT()
   at System.Activator.CreateInstance[T]()
   at WinRT.WeakLazy`1.get_Value()
   at WinRT.ActivationFactory`1.ActivateInstance[I]()
   at Microsoft.Graphics.Canvas.Effects.GaussianBlurEffect..ctor()
   at CommunityToolkit.WinUI.UI.Media.Pipelines.PipelineBuilder.<>c__DisplayClass12_0.<<Blur>g__Factory|0>d.MoveNext()
--- End of stack trace from previous location ---
   at CommunityToolkit.WinUI.UI.Media.Pipelines.PipelineBuilder.BuildAsync()
   at CommunityToolkit.WinUI.UI.Media.PipelineVisualFactoryBase.GetAttachedVisualAsync(UIElement element)
   at CommunityToolkit.WinUI.UI.Media.PipelineVisualFactory.GetAttachedVisualAsync(UIElement element)
   at CommunityToolkit.WinUI.UI.Media.UIElementExtensions.<>c__DisplayClass3_0.<<OnVisualFactoryPropertyChanged>g__Set|0>d.MoveNext()
--- End of stack trace from previous location ---
   at CommunityToolkit.WinUI.UI.Media.UIElementExtensions.<>c__DisplayClass3_0.<<OnVisualFactoryPropertyChanged>g__Element_Loaded|1>d.MoveNext()
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.<>c__DisplayClass2_0.<Post>b__0()

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

Other Windows Build number

Windows 10 22H2 (Build 19045.2006)

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)
  • Other (specify)

Other SDK version

No response

Visual Studio Version

2022

Visual Studio Build Number

17.5.1

Device form factor

Desktop

Nuget packages

CommunityToolkit.WinUI.UI.Media (7.1.2)
Microsoft.Windows.SDK.BuildTools (10.0.22621.755)
Microsoft.WindowsAppSDK (1.2.221109.1)
System.Diagnostics.EventLog (7.0.0)

Additional context

Application is built as 64-bit and run on a Hyper-V VM under Windows 10 21H2 (19044.2604) on an Intel Core i5-7500T CPU.

Help us help you

No.

@kjean667 kjean667 added the bug 🐛 An unexpected issue that highlights incorrect behavior label Mar 13, 2023
@ghost ghost added the needs triage 🔍 label Mar 13, 2023
@ghost
Copy link

ghost commented Mar 13, 2023

Hello kjean667, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

@michael-hawker michael-hawker added brush 🖌️ WinUI 💠 Related to WinUI 3 Version or when paired with External can mean requires fix in WinUI 2/3. and removed needs triage 🔍 labels Mar 13, 2023
@michael-hawker
Copy link
Member

@Sergio0694 any of this looks familiar to you? Is there some Win2D or other device check we may be missing for WindowsAppSDK that we wouldn't need to do in UWP? (Or maybe this is an issue there too?)

@Sergio0694
Copy link
Member

That at Microsoft.Graphics.Canvas.Effects.GaussianBlurEffect..ctor() line is suspect, that shouldn't possibly crash (and that "class not registered" is weird in this context). As a sanity check, does just creating new GaussianBlurEffect() also fail in the VM?

@kjean667
Copy link
Author

@Sergio0694 Yes, new GaussianBlurEffect() fails and throws an unhandled exception if run in code behind when for example the Loaded event is triggered by a Page.

Stack trace of new GaussianBlurEffect():

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.Runtime.InteropServices.COMException (0x80040154): Klassen har inte registrerats (0x80040154 (REGDB_E_CLASSNOTREG))
   at WinRT.BaseActivationFactory..ctor(String typeNamespace, String typeFullName)
   at WinRT.ActivationFactory`1..ctor()
   at System.RuntimeType.CreateInstanceOfT()
   --- End of inner exception stack trace ---
   at System.RuntimeType.CreateInstanceOfT()
   at System.Activator.CreateInstance[T]()
   at WinRT.WeakLazy`1.get_Value()
   at WinRT.ActivationFactory`1.ActivateInstance[I]()
   at Microsoft.Graphics.Canvas.Effects.GaussianBlurEffect..ctor()
   at PipelineVisualFactoryBug.MainPage.MainPage_Loaded(Object sender, RoutedEventArgs e)
   at WinRT._EventSource_global__Microsoft_UI_Xaml_RoutedEventHandler.EventState.<GetEventInvoke>b__1_0(Object sender, RoutedEventArgs e)
   at ABI.Microsoft.UI.Xaml.RoutedEventHandler.Do_Abi_Invoke(IntPtr thisPtr, IntPtr sender, IntPtr e)

As a side note, the unhandled exception does not crash the application (but is still thrown as an unhandled exception) if it is triggered from the MainWindow (class Window) object. However if the blur effect is created by a Page it will crash the application. I.e. if the MainWindow contains a Page reference that uses GaussianBlurEffect it will crash the entire application. In my stack trace above, the MainWindow.xaml contains a Page called MainPage. The MainPage code behind looks like this in the stack trace above:

  public sealed partial class MainPage : Page
  {
    private GaussianBlurEffect blur;
    public MainPage()
    {
      InitializeComponent();

      Loaded += MainPage_Loaded;
    }

    private void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
      blur = new GaussianBlurEffect();
    }
  }

@lunelake
Copy link

lunelake commented Apr 26, 2023

I also received error reports from users for the same issue, and it doesn't seem to be limited to just VMs. The user is running Windows 11 (10.0.22621.1555) on a Dell desktop model, OptiPlex 980, and reported the same error.

To test it out, I installed the WinUI3-developed app on a VM and found that the Fallback Color wasn't displayed correctly. In contrast, the UWP-developed app displayed the Blur effect correctly despite having the same code.

I didn't encounter the issue on the devices I tested, but after the app was released, several errors were reported on various devices, and I'm not sure of the cause.

@zhuxb711
Copy link

Solution: #4963 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
brush 🖌️ bug 🐛 An unexpected issue that highlights incorrect behavior WinUI 💠 Related to WinUI 3 Version or when paired with External can mean requires fix in WinUI 2/3.
Projects
None yet
Development

No branches or pull requests

5 participants