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

WinAppSDK crash on startup when using most Material styles #361

Closed
kazo0 opened this issue Sep 21, 2023 · 15 comments
Closed

WinAppSDK crash on startup when using most Material styles #361

kazo0 opened this issue Sep 21, 2023 · 15 comments
Assignees
Labels
kind/bug Something isn't working

Comments

@kazo0
Copy link
Contributor

kazo0 commented Sep 21, 2023

Installing latest dev templates with dotnet new install uno.templates::5.0.0-dev.486 and running dotnet new unoapp -o MyTestApp results in a crash on startup when running the Windows head:

1fd461f4-747a-420c-9aed-371ccf49768d

With latest VS Stable and VS Preview

App starts fine if I use dotnet new unoapp -preset=blank -o MyTestApp

@kazo0 kazo0 added the kind/bug Something isn't working label Sep 21, 2023
@nickrandolph
Copy link
Contributor

This is a result of using the FilledButtonStyle on a Button

@kazo0
Copy link
Contributor Author

kazo0 commented Oct 4, 2023

The error is this:

Exception thrown at 0x00007FFB487A535C (KernelBase.dll) in MaterialTestApp.Windows.exe: WinRT originate error - 0x802B000A : 'Failed to assign to property 'Microsoft.UI.Xaml.UIElement.Visibility'. [Line: 0 Position: 0]'.

And it seems to be happening with any control that has this in the template:

Visibility="{Binding Path=(um:ControlExtensions.Icon), RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource MaterialNullToCollapsedConverter}, FallbackValue=Collapsed, TargetNullValue=Collapsed}"

It looks like there's been a change in winui surrounding this? Can no longer have the converter return a string of "Visible" or "Collapsed", if I instead make it return a Visiblity enum value or create Visibility StaticResources and set those as the properties of the converter then it works

<Visibility x:Key="VisibleVal">Visible</Visibility>
	<Visibility x:Key="CollapsedVal">Collapsed</Visibility>
	<local:MyConverter x:Key="MaterialNullToCollapsedConverter"
								 NotNullValue="{StaticResource VisibleVal}"
								 NullValue="{StaticResource CollapsedVal}" />

@kazo0 kazo0 transferred this issue from unoplatform/uno.templates Oct 4, 2023
@kazo0 kazo0 changed the title Windows crash on startup with latest dev templates WinAppSDK crash on startup when using most Material styles Oct 4, 2023
@kazo0 kazo0 self-assigned this Oct 4, 2023
@Xiaoy312
Copy link
Contributor

Xiaoy312 commented Oct 4, 2023

would it work if you used string literals "True" "False" directly on the converter's properties?

@kazo0
Copy link
Contributor Author

kazo0 commented Oct 4, 2023

@Xiaoy312

Using True/False doesn't cause a crash but it also doesn't work and just stays as Visible no matter what MyProp is.

So basically MyConverter3 is where the crash occurs

<Page x:Class="MaterialTestApp.MainPage"
	  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	  xmlns:local="using:MaterialTestApp"
	  xmlns:um="using:Uno.Material"
	  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	  xmlns:maui="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	  xmlns:not_maui="http://notmaui"
	  mc:Ignorable="d not_maui"
	  Background="{ThemeResource BackgroundBrush}">
	<Page.Resources>
		<Visibility x:Key="VisibleVal">Visible</Visibility>
		<Visibility x:Key="CollapsedVal">Collapsed</Visibility>
		
		<local:MyConverter x:Key="MyConverter1"
						   FalseValue="{StaticResource CollapsedVal}"
						   TrueValue="{StaticResource VisibleVal}" />

		<local:MyConverter x:Key="MyConverter2"
						   FalseValue="False"
						   TrueValue="True" />

		<local:MyConverter x:Key="MyConverter3"
						   FalseValue="Collapsed"
						   TrueValue="Visible" />
	</Page.Resources>
	<StackPanel HorizontalAlignment="Center"
				VerticalAlignment="Center">
		<Button Content="Toggle MyProp"
				Click="Button_Click" />
		
		<!--Works-->
		<CheckBox Content="Converter 1" Visibility="{Binding MyProp, Converter={StaticResource MyConverter1}}" />
		
		<!--Compiles but doesn't toggle Visibility-->
		<CheckBox Content="Converter 2" Visibility="{Binding MyProp, Converter={StaticResource MyConverter2}}" />
		
		<!--Crashes-->
		<CheckBox Content="Converter 3" Visibility="{Binding MyProp, Converter={StaticResource MyConverter3}}" />
	</StackPanel>
</Page>

@kazo0
Copy link
Contributor Author

kazo0 commented Oct 4, 2023

I'm curious why this started happening but since this looks like a WinAppSDK thing, I guess we should just create some sort of specific NullToVisibilityConverter and use that instead?

@kazo0
Copy link
Contributor Author

kazo0 commented Oct 6, 2023

After discussion, we will refactor the Uno.Themes repo to find any places where we are using a Converter with parameters for the Visiblity and instead use a new converter that is specific for Visibility that returns a strongly-typed Visibility enum

@kazo0 kazo0 removed their assignment Oct 6, 2023
@Arieldelossantos Arieldelossantos self-assigned this Oct 10, 2023
@Arieldelossantos
Copy link
Contributor

only for Uno.Material?? or we need to do the replacement on the Uno.Cupertino styles?? @kazo0

@kazo0
Copy link
Contributor Author

kazo0 commented Oct 10, 2023

@Arieldelossantos on second thought, could you maybe spend some time trying to investigate why this crash is happening on Windows? I can't seem to get it to crash on Chefs or any other app that I update to the latest WinAppSdk version. You should be able to get it to crash by just doing
dotnet new install uno.templates::5.0.0-dev.486 (or any later -dev.X version)
dotnet new unoapp -preset blank -theme material -o MaterialTestApp -skip
and then adding a button to the MainPage.xaml of your sample app

@Arieldelossantos
Copy link
Contributor

created this Draft PR @kazo0 just to check whether this would be the solution to your initial thoughts... i'm investigating the crash on the app to see if i can find something wrong

@kazo0
Copy link
Contributor Author

kazo0 commented Oct 12, 2023

@Arieldelossantos Can you try creating a new WinAppSDK app from Visual Studio (not an Uno app, an actual Windows app) and attempt to reproduce this behavior in both an Unpackaged and Packaged version of a Windows app?

@kazo0
Copy link
Contributor Author

kazo0 commented Oct 12, 2023

@Arieldelossantos In order to test, create an native Windows app and use this converter

public class MyConverter : IValueConverter
{
	public object FalseValue { get; set; }
	public object TrueValue { get; set; }

	public object Convert(object value, Type targetType, object parameter, string language)
	{
		if (value is bool b)
		{
			return b ? TrueValue : FalseValue;
		}
		return FalseValue;
	}

	public object ConvertBack(object value, Type targetType, object parameter, string language)
	{
		throw new NotImplementedException();
	}
}

With your XAML looking similar to:

<Page x:Class="UnoApp73.MainPage"
	  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	  xmlns:local="using:UnoApp73"
	  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	  mc:Ignorable="d"
	  Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
	<Page.Resources>
		<local:MyConverter x:Key="MyConverter"
						   FalseValue="Collapsed"
						   TrueValue="Visible" />
	</Page.Resources>

	<StackPanel HorizontalAlignment="Center"
				VerticalAlignment="Center">
		<CheckBox Content="Toggle"
				  x:Name="MyCheckBox" />

		<Button Content="Test"
				Visibility="{Binding ElementName=MyCheckBox, Path=IsChecked, Converter={StaticResource MyConverter}}" />
	</StackPanel>
</Page>

And see if it crashes

@kazo0
Copy link
Contributor Author

kazo0 commented Oct 12, 2023

@Arieldelossantos Actually, can you try with latest templates dotnet new install uno.templates::5.0.0-dev.525 and doing a dotnet new unoapp -o MyTestApp and see if it still crashes on Windows, without making any other modifications? It's no longer crashing for me

@Arieldelossantos
Copy link
Contributor

it's still crashing for me @kazo0 :/

@agneszitte
Copy link
Contributor

Related issue : microsoft/microsoft-ui-xaml#9021

@agneszitte agneszitte transferred this issue from unoplatform/Uno.Themes Oct 27, 2023
@nickrandolph
Copy link
Contributor

Closing this as it's been resolved by removing trimming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants