From 7bafdc87b7a8aac2e1b8a794bacb02d3555b775d Mon Sep 17 00:00:00 2001 From: lindexi Date: Thu, 5 Mar 2026 10:03:35 +0800 Subject: [PATCH] Put the re create surface to trycatch block. Solve the `transaction` do not be disposed when CreateSurface exception. --- .../WinUiCompositedWindowSurface.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Windows/Avalonia.Win32/WinRT/Composition/WinUiCompositedWindowSurface.cs b/src/Windows/Avalonia.Win32/WinRT/Composition/WinUiCompositedWindowSurface.cs index 798a580bd5..ee4c326fd6 100644 --- a/src/Windows/Avalonia.Win32/WinRT/Composition/WinUiCompositedWindowSurface.cs +++ b/src/Windows/Avalonia.Win32/WinRT/Composition/WinUiCompositedWindowSurface.cs @@ -142,24 +142,24 @@ namespace Avalonia.Win32.WinRT.Composition throw new RenderTargetCorruptedException(); var transaction = _window.BeginTransaction(); - bool forceResize = false; - var supportTransparency = _drawingSurface.AlphaMode == DirectXAlphaMode.Premultiplied; - if (_window.IsTransparency != supportTransparency) + bool needsEndDraw = false; + try { - // Re-create the surface with correct alpha mode if the transparency support is not correct. This can happen when the transparency level is changed. - _surface.Dispose(); - _surfaceInterop.Dispose(); - _drawingSurface.Dispose(); + bool forceResize = false; + var supportTransparency = _drawingSurface.AlphaMode == DirectXAlphaMode.Premultiplied; + if (_window.IsTransparency != supportTransparency) + { + // Re-create the surface with correct alpha mode if the transparency support is not correct. This can happen when the transparency level is changed. + _surface.Dispose(); + _surfaceInterop.Dispose(); + _drawingSurface.Dispose(); - CreateSurface(_window); + CreateSurface(_window); - // The _drawingSurface.Size != _size, so that require force resize to update the size of surface. - forceResize = true; - } + // The _drawingSurface.Size != _size, so that require force resize to update the size of surface. + forceResize = true; + } - bool needsEndDraw = false; - try - { var size = _window.WindowInfo.Size; var scale = _window.WindowInfo.Scaling; _window.ResizeIfNeeded(size);