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

PipelineBuilder throw a NullReferenceException #235

Closed
zou-z opened this issue Sep 12, 2023 · 6 comments · Fixed by #299
Closed

PipelineBuilder throw a NullReferenceException #235

zou-z opened this issue Sep 12, 2023 · 6 comments · Fixed by #299
Assignees
Labels
regression What was working is now broke

Comments

@zou-z
Copy link

zou-z commented Sep 12, 2023

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.
@zou-z
Copy link
Author

zou-z commented Sep 12, 2023

Screenshots
image
image
image
image

@michael-hawker
Copy link
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

@zou-z
Copy link
Author

zou-z commented Sep 20, 2023

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>

@Cornmarket
Copy link

I have a similar issue in a winui project #238

@Marv51
Copy link

Marv51 commented Oct 16, 2023

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

@michael-hawker
Copy link
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

@Arlodotexe Arlodotexe self-assigned this Nov 2, 2023
@Arlodotexe Arlodotexe added the regression What was working is now broke label Nov 2, 2023
@Arlodotexe Arlodotexe moved this from 🆕 New to 🔖 Ready in Toolkit 8.x Nov 2, 2023
@Arlodotexe Arlodotexe moved this from 🔖 Ready to 🏗 In progress in Toolkit 8.x Nov 2, 2023
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression What was working is now broke
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants