Browse Source

Put the re create surface to trycatch block.

Solve the `transaction` do not be disposed when CreateSurface exception.
pull/20879/head
lindexi 6 months ago
parent
commit
7bafdc87b7
  1. 28
      src/Windows/Avalonia.Win32/WinRT/Composition/WinUiCompositedWindowSurface.cs

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

Loading…
Cancel
Save