Browse Source

Add code to re-create a render target and re-render the frame when the render target gets corrupted. Should fix #521

pull/664/head
Jeremy Koritzinsky 10 years ago
parent
commit
c3fb89ee73
  1. 12
      src/Avalonia.Controls/Platform/ITopLevelRenderer.cs
  2. 1
      src/Avalonia.SceneGraph/Avalonia.SceneGraph.csproj
  3. 30
      src/Avalonia.SceneGraph/RenderTargetCorruptedException.cs
  4. 9
      src/Windows/Avalonia.Direct2D1/Media/DrawingContext.cs

12
src/Avalonia.Controls/Platform/ITopLevelRenderer.cs

@ -38,7 +38,17 @@ namespace Avalonia.Controls.Platform
topLevel.PlatformImpl.Paint = rect =>
{
viewport.Render(topLevel);
try
{
viewport.Render(topLevel);
}
catch (RenderTargetCorruptedException ex)
{
Logging.Logger.Error("Renderer", this, "Render target was corrupted. Exception: {0}", ex);
viewport.Dispose();
viewport = PlatformManager.CreateRenderTarget(topLevel.PlatformImpl);
topLevel.PlatformImpl.Paint(rect); // Retry painting
}
queueManager.RenderFinished();
};

1
src/Avalonia.SceneGraph/Avalonia.SceneGraph.csproj

@ -100,6 +100,7 @@
<Compile Include="Media\FormattedText.cs" />
<Compile Include="Media\Geometry.cs" />
<Compile Include="Media\IDrawingContext.cs" />
<Compile Include="RenderTargetCorruptedException.cs" />
<Compile Include="VisualTree\IVisual.cs" />
<Compile Include="Media\Imaging\Bitmap.cs" />
<Compile Include="Media\Imaging\IBitmap.cs" />

30
src/Avalonia.SceneGraph/RenderTargetCorruptedException.cs

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Avalonia
{
public class RenderTargetCorruptedException : Exception
{
public RenderTargetCorruptedException()
{
}
public RenderTargetCorruptedException(string message)
: base(message)
{
}
public RenderTargetCorruptedException(Exception innerException)
: base(null, innerException)
{
}
public RenderTargetCorruptedException(string message, Exception innerException)
: base(message, innerException)
{
}
}
}

9
src/Windows/Avalonia.Direct2D1/Media/DrawingContext.cs

@ -57,7 +57,14 @@ namespace Avalonia.Direct2D1.Media
{
foreach (var layer in _layerPool)
layer.Dispose();
_renderTarget.EndDraw();
try
{
_renderTarget.EndDraw();
}
catch (SharpDXException ex) when((uint)ex.HResult == 0x8899000C) // D2DERR_RECREATE_TARGET
{
throw new RenderTargetCorruptedException(ex);
}
}
/// <summary>

Loading…
Cancel
Save