Fixed memory leak and duplicate initialization in WinUI panel
このコミットが含まれているのは:
1 親
66d78cc4e9
コミット
919dd15914
3ファイル変更
+51
-7
検索条件に一致するファイルはありません
+3
-3
@@ -107,9 +107,9 @@
|
||||
ShaderRunner="{x:Bind ShaderRunner}"/>
|
||||
|
||||
<!--Note: here we have a selection property to work around {x:Bind} not working correctly outside of the
|
||||
current template scope. Once that's fixed in WinUI 3, this can be rewritten as a multi-binding like this:
|
||||
Visibility="{x:Bind system:Object.ReferenceEquals((local:ComputeShader), ViewModel.SelectedComputeShader), Mode=OneWay}".
|
||||
When that is working, the ComputeShader.IsSelected property can also be removed, as it will no longer be needed.-->
|
||||
current template scope. Once that's fixed in WinUI 3, this can be rewritten as a multi-binding like this:
|
||||
Visibility="{x:Bind system:Object.ReferenceEquals((local:ComputeShader), ViewModel.SelectedComputeShader), Mode=OneWay}".
|
||||
When that is working, the ComputeShader.IsSelected property can also be removed, as it will no longer be needed.-->
|
||||
<Border
|
||||
BorderThickness="4"
|
||||
BorderBrush="White"
|
||||
|
||||
@@ -116,18 +116,30 @@ namespace ComputeSharp.WinUI
|
||||
/// <summary>
|
||||
/// Indicates whether or not the rendering has been canceled.
|
||||
/// </summary>
|
||||
private bool isCancellationRequested;
|
||||
private volatile bool isCancellationRequested;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Stopwatch"/> instance tracking time since the first rendered frame.
|
||||
/// </summary>
|
||||
private Stopwatch? renderStopwatch;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether or not <see cref="OnInitialize"/> has already been called.
|
||||
/// </summary>
|
||||
private bool isInitialized;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the current application.
|
||||
/// </summary>
|
||||
private unsafe void OnInitialize()
|
||||
{
|
||||
if (isInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isInitialized = true;
|
||||
|
||||
// Get the underlying ID3D12Device in use
|
||||
fixed (ID3D12Device** d3D12Device = this.d3D12Device)
|
||||
{
|
||||
@@ -160,10 +172,8 @@ namespace ComputeSharp.WinUI
|
||||
}
|
||||
|
||||
// Create the swap chain to display frames
|
||||
using (ComPtr<IDXGISwapChain1> dxgiSwapChain1 = default)
|
||||
using (ComPtr<IDXGIFactory2> dxgiFactory2 = default)
|
||||
{
|
||||
using ComPtr<IDXGIFactory2> dxgiFactory2 = default;
|
||||
|
||||
FX.CreateDXGIFactory2(FX.DXGI_CREATE_FACTORY_DEBUG, FX.__uuidof<IDXGIFactory2>(), (void**)dxgiFactory2.GetAddressOf()).Assert();
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC1 dxgiSwapChainDesc1 = default;
|
||||
@@ -179,6 +189,8 @@ namespace ComputeSharp.WinUI
|
||||
dxgiSwapChainDesc1.SwapEffect = DXGI_SWAP_EFFECT.DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
||||
dxgiSwapChainDesc1.BufferUsage = FX.DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
|
||||
using ComPtr<IDXGISwapChain1> dxgiSwapChain1 = default;
|
||||
|
||||
dxgiFactory2.Get()->CreateSwapChainForComposition(
|
||||
(IUnknown*)this.d3D12CommandQueue.Get(),
|
||||
&dxgiSwapChainDesc1,
|
||||
@@ -442,5 +454,29 @@ namespace ComputeSharp.WinUI
|
||||
{
|
||||
this.isCancellationRequested = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the current render loop, and releases all resources.
|
||||
/// </summary>
|
||||
private void OnDisposed()
|
||||
{
|
||||
this.isCancellationRequested = true;
|
||||
|
||||
// Ensure the rendering has stopped
|
||||
if (this.renderThread is Thread renderThread)
|
||||
{
|
||||
renderThread.Join();
|
||||
}
|
||||
|
||||
this.d3D12Device.Dispose();
|
||||
this.d3D12CommandQueue.Dispose();
|
||||
this.d3D12Fence.Dispose();
|
||||
this.d3D12CommandAllocator.Dispose();
|
||||
this.d3D12GraphicsCommandList.Dispose();
|
||||
this.dxgiSwapChain2.Dispose();
|
||||
this.d3D12Resource0.Dispose();
|
||||
this.d3D12Resource1.Dispose();
|
||||
this.texture?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,14 @@ namespace ComputeSharp.WinUI
|
||||
this.CompositionScaleChanged += ComputeShaderPanel_CompositionScaleChanged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizes the current <see cref="ComputeShaderPanel"/> instance and releases all resources.
|
||||
/// </summary>
|
||||
~ComputeShaderPanel()
|
||||
{
|
||||
OnDisposed();
|
||||
}
|
||||
|
||||
// Initializes the swap chain and starts the render thread
|
||||
private void ComputeShaderPanel_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする