From 3f759a78c6f1ff739b6bbf1fe27aa4812d8cbd81 Mon Sep 17 00:00:00 2001 From: Alex Maitland Date: Tue, 15 Feb 2022 14:06:35 +1000 Subject: [PATCH] WPF - CompositionTargetRenderHandler add null check --- .../Experimental/CompositionTargetRenderHandler.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CefSharp.Wpf/Rendering/Experimental/CompositionTargetRenderHandler.cs b/CefSharp.Wpf/Rendering/Experimental/CompositionTargetRenderHandler.cs index 9158cf2462..c4dd852b53 100644 --- a/CefSharp.Wpf/Rendering/Experimental/CompositionTargetRenderHandler.cs +++ b/CefSharp.Wpf/Rendering/Experimental/CompositionTargetRenderHandler.cs @@ -8,7 +8,6 @@ using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Imaging; -using System.Windows.Threading; using Rect = CefSharp.Structs.Rect; namespace CefSharp.Wpf.Rendering.Experimental @@ -25,6 +24,12 @@ public class CompositionTargetRenderHandler : IRenderHandler private readonly object lockObj = new object(); private ChromiumWebBrowser browser; + /// + /// Default constructor + /// + /// ChromiumWebBrowser instance + /// DPI X + /// DPI Y public CompositionTargetRenderHandler(ChromiumWebBrowser browser, double dpiX, double dpiY) { this.browser = browser; @@ -103,7 +108,7 @@ private void OnRendering(object sender, EventArgs args) private void UpdateImage(PaintElement element) { - if (element.IsDirty && element.Image != null) + if (element != null && element.IsDirty && element.Image != null) { var bitmap = element.Image.Source as WriteableBitmap; if (bitmap == null || bitmap.PixelWidth != element.Width || bitmap.PixelHeight != element.Height)