Skip to content

PipelineBuilder throw a NullReferenceException #235

Closed

Description

@zou-z

Describe the bug

I copied sample code from BlurEffectAnimation to my project.Then it throw a NullReferenceException when i run my winui3 application.
image

Steps to reproduce

Copy sample code to MainWindow.xaml and run application

<?xml version="1.0" encoding="utf-8"?>
<Window
    x:Class="BlurTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:BlurTest"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
      xmlns:ani="using:CommunityToolkit.WinUI.Animations"
      xmlns:behaviors="using:CommunityToolkit.WinUI.Behaviors"
      xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
      xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
      xmlns:media="using:CommunityToolkit.WinUI.Media">
    <Grid>
        <Border Height="280">
            <Image VerticalAlignment="Center"
               Source="ms-appx:///Assets/StoreLogo.png" />

            <media:UIElementExtensions.VisualFactory>
                <media:PipelineVisualFactory>
                    <media:BlurEffect x:Name="ImageBlurEffect"
                                  IsAnimatable="True" />
                </media:PipelineVisualFactory>
            </media:UIElementExtensions.VisualFactory>

            <ani:Explicit.Animations>
                <ani:AnimationSet x:Name="BlurAnimation"
                              IsSequential="True">
                    <ani:BlurEffectAnimation EasingMode="EaseOut"
                                         EasingType="Linear"
                                         Target="{x:Bind ImageBlurEffect}"
                                         From="0"
                                         To="8"
                                         Duration="0:0:3" />

                    <ani:BlurEffectAnimation EasingMode="EaseOut"
                                         EasingType="Linear"
                                         Target="{x:Bind ImageBlurEffect}"
                                         From="8"
                                         To="0"
                                         Duration="0:0:3" />
                </ani:AnimationSet>
            </ani:Explicit.Animations>

            <interactivity:Interaction.Behaviors>
                <interactions:EventTriggerBehavior EventName="Loaded">
                    <behaviors:StartAnimationAction Animation="{x:Bind BlurAnimation}" />
                </interactions:EventTriggerBehavior>
            </interactivity:Interaction.Behaviors>
        </Border>

    </Grid>
</Window>


### Expected behavior

MainWindow play blur animation after start.

### Screenshots

![image](https://github.com/CommunityToolkit/Windows/assets/45748083/6dcdc196-7d1e-415f-8856-027e2678543e)
![image](https://github.com/CommunityToolkit/Windows/assets/45748083/700a2d6f-6475-4b4c-a550-f12cce423d7d)
![image](https://github.com/CommunityToolkit/Windows/assets/45748083/372d25c4-a096-4f48-94ab-60e7e5219508)
![image](https://github.com/CommunityToolkit/Windows/assets/45748083/ec486d65-1a7b-441b-951e-55d90bfb5999)


### 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)
- [X] 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)
- [X] 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

Desktop

### Additional context

_No response_

### Help us help you

Yes, I'd like to be assigned to work on this item.

Activity

  1. zou-z commented on Sep 12, 2023

    @zou-z
    Author

    Screenshots
    image
    image
    image
    image

  2. michael-hawker commented on Sep 19, 2023

    @michael-hawker
    Member

    @zou-z can you try putting everything in a Page over in the root Window? As I may guess that the x:Bind may not be working? See microsoft/microsoft-ui-xaml#4966

    This template could help with that to also compare against UWP: https://github.com/michael-hawker/WinUI2Plus3Template

  3. zou-z commented on Sep 20, 2023

    @zou-z
    Author

    I tried, but it still didn't work and the same error occurred.I even deleted the x:Bind

    <Page
        x:Class="BlurTest.BlankPage1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:BlurTest"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
          xmlns:ani="using:CommunityToolkit.WinUI.Animations"
          xmlns:behaviors="using:CommunityToolkit.WinUI.Behaviors"
          xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
          xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
          xmlns:media="using:CommunityToolkit.WinUI.Media">
    
        <Grid>
            <Border Height="280">
                <Image VerticalAlignment="Center"
                   Source="ms-appx:///Assets/StoreLogo.png" />
    
                <media:UIElementExtensions.VisualFactory>
                    <media:PipelineVisualFactory>
                        <media:BlurEffect />
                    </media:PipelineVisualFactory>
                </media:UIElementExtensions.VisualFactory>
              
            </Border>
    
        </Grid>
    </Page>
    
  4. Cornmarket commented on Sep 21, 2023

    @Cornmarket

    I have a similar issue in a winui project #238

  5. Marv51 commented on Oct 16, 2023

    @Marv51

    I think this might be caused by calls to "Window.Current.Compositor". In the PipelineBuilder.cs file I fould 3 instances. That does not work in WinUI 3. I think this is the same bug as #233.

    The spots i am talking about are:

    var factory = this.animationProperties.Count > 0
    ? Window.Current.Compositor.CreateEffectFactory(effect, this.animationProperties)
    : Window.Current.Compositor.CreateEffectFactory(effect);

    SpriteVisual visual = Window.Current.Compositor.CreateSpriteVisual();

  6. michael-hawker commented on Oct 16, 2023

    @michael-hawker
    Member

    Looks like this was missed in porting. @Arlodotexe can you compare against the old branch, seems like updating the Compositor wasn't brought over for WinUI 3 in a few places now, see for instance:

    https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/080bdb99e6810eb2157ad635f00e64a64acabb50/CommunityToolkit.WinUI.UI.Media/Pipelines/PipelineBuilder.cs#L170-L172

  7. self-assigned this
    on Nov 2, 2023
  8. moved this from 🆕 New to 🔖 Ready in Toolkit 8.xon Nov 2, 2023
  9. moved this from 🔖 Ready to 🏗 In progress in Toolkit 8.xon Nov 2, 2023
  10. moved this from 🏗 In progress to 👀 In review in Toolkit 8.xon Dec 12, 2023
  11. moved this from 👀 In review to ✅ Done in Toolkit 8.xon Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

regressionWhat was working is now broke

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions