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(); throw new RenderTargetCorruptedException();
var transaction = _window.BeginTransaction(); var transaction = _window.BeginTransaction();
bool forceResize = false; bool needsEndDraw = false;
var supportTransparency = _drawingSurface.AlphaMode == DirectXAlphaMode.Premultiplied; try
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. bool forceResize = false;
_surface.Dispose(); var supportTransparency = _drawingSurface.AlphaMode == DirectXAlphaMode.Premultiplied;
_surfaceInterop.Dispose(); if (_window.IsTransparency != supportTransparency)
_drawingSurface.Dispose(); {
// 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. // The _drawingSurface.Size != _size, so that require force resize to update the size of surface.
forceResize = true; forceResize = true;
} }
bool needsEndDraw = false;
try
{
var size = _window.WindowInfo.Size; var size = _window.WindowInfo.Size;
var scale = _window.WindowInfo.Scaling; var scale = _window.WindowInfo.Scaling;
_window.ResizeIfNeeded(size); _window.ResizeIfNeeded(size);

Loading…
Cancel
Save