Improve WinUI 3 sample app (#295)

* Fix WinUI sample app crash when closing

* Tweak WinUI 3 sample project files

Also disables ReadyToRun for Debug builds
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2022-05-28 00:49:14 +02:00
1 親 76a83967dc
コミット 84b79f0f9b
6ファイル変更
+69 -27

検索条件に一致するファイルはありません

+1 -1
ファイルの表示
@@ -119,7 +119,7 @@
<Grid>
<!-- Shader preview -->
<computesharp:AnimatedComputeShaderPanel ShaderRunner="{x:Bind ShaderRunner}" />
<computesharp:AnimatedComputeShaderPanel Loaded="AnimatedComputeShaderPanel_Loaded" ShaderRunner="{x:Bind ShaderRunner}" />
<!--
Note: here we have a selection property to work around {x:Bind} not working correctly outside of the
+26
ファイルの表示
@@ -1,6 +1,8 @@
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.SwapChain.Core.Services;
using ComputeSharp.SwapChain.Core.ViewModels;
using ComputeSharp.WinUI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
@@ -11,6 +13,11 @@ namespace ComputeSharp.SwapChain.WinUI.Views;
/// </summary>
public sealed partial class MainWindow : Window
{
/// <summary>
/// The mapping of currently alive shader panels.
/// </summary>
private readonly ConditionalWeakTable<AnimatedComputeShaderPanel, object?> shaderPanels = new();
public MainWindow()
{
this.InitializeComponent();
@@ -26,6 +33,19 @@ public sealed partial class MainWindow : Window
/// </summary>
public MainViewModel ViewModel => (MainViewModel)Root.DataContext;
/// <summary>
/// Stops all rendering when the application is closing.
/// </summary>
public void OnShutdown()
{
ShaderPanel.ShaderRunner = null;
foreach (var (panel, _) in this.shaderPanels)
{
panel.ShaderRunner = null;
}
}
// Opens the shader selection panel
private void OpenShaderSelectionPanelButton_Click(object sender, RoutedEventArgs e)
{
@@ -44,4 +64,10 @@ public sealed partial class MainWindow : Window
{
ShadersListContainerPanel.Height = Math.Round(e.Size.Height * 0.35);
}
// Tracks the current panel
private void AnimatedComputeShaderPanel_Loaded(object sender, RoutedEventArgs e)
{
this.shaderPanels.AddOrUpdate((AnimatedComputeShaderPanel)sender, null);
}
}