From c208e93281a8293a49a97d3f82ca8aea643fb971 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Sat, 17 Dec 2022 01:30:16 +0600 Subject: [PATCH] Logging --- .../Server/ServerCustomCompositionVisual.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Base/Rendering/Composition/Server/ServerCustomCompositionVisual.cs b/src/Avalonia.Base/Rendering/Composition/Server/ServerCustomCompositionVisual.cs index 555972876d..227df87a87 100644 --- a/src/Avalonia.Base/Rendering/Composition/Server/ServerCustomCompositionVisual.cs +++ b/src/Avalonia.Base/Rendering/Composition/Server/ServerCustomCompositionVisual.cs @@ -12,7 +12,7 @@ internal class ServerCompositionCustomVisual : ServerCompositionContainerVisual, private bool _wantsNextAnimationFrameAfterTick; internal ServerCompositionCustomVisual(ServerCompositor compositor, CompositionCustomVisualHandler handler) : base(compositor) { - _handler = handler; + _handler = handler ?? throw new ArgumentNullException(nameof(handler)); _handler.Attach(this); } @@ -29,7 +29,7 @@ internal class ServerCompositionCustomVisual : ServerCompositionContainerVisual, catch (Exception e) { Logger.TryGet(LogEventLevel.Error, LogArea.Visual) - ?.Log(_handler, $"Exception in {nameof(CompositionCustomVisualHandler)} {{0}}", e); + ?.Log(_handler, $"Exception in {_handler.GetType().Name}.{nameof(CompositionCustomVisualHandler.OnMessage)} {{0}}", e); } } } @@ -68,7 +68,15 @@ internal class ServerCompositionCustomVisual : ServerCompositionContainerVisual, protected override void RenderCore(CompositorDrawingContextProxy canvas, Rect currentTransformedClip) { - var context = new ImmediateDrawingContext(canvas, false); - _handler.OnRender(context); + using var context = new ImmediateDrawingContext(canvas, false); + try + { + _handler.OnRender(context); + } + catch (Exception e) + { + Logger.TryGet(LogEventLevel.Error, LogArea.Visual) + ?.Log(_handler, $"Exception in {_handler.GetType().Name}.{nameof(CompositionCustomVisualHandler.OnRender)} {{0}}", e); + } } } \ No newline at end of file