diff --git a/CefSharp.Wpf/Rendering/InteropBitmapInfo.cs b/CefSharp.Wpf/Rendering/InteropBitmapInfo.cs index d0571c64a7..5dc53a0b69 100644 --- a/CefSharp.Wpf/Rendering/InteropBitmapInfo.cs +++ b/CefSharp.Wpf/Rendering/InteropBitmapInfo.cs @@ -2,6 +2,7 @@ // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. +using System; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; @@ -31,14 +32,25 @@ public override void ClearBitmap() public override void Invalidate() { - Bitmap.Invalidate(); + if (Bitmap != null) + { + Bitmap.Invalidate(); + } } public override BitmapSource CreateBitmap() { var stride = Width * BytesPerPixel; - Bitmap = (InteropBitmap)Imaging.CreateBitmapSourceFromMemorySection(FileMappingHandle, Width, Height, PixelFormat, stride, 0); + // Unable to create bitmap without valid File Handle (Most likely control is being disposed) + if (FileMappingHandle == IntPtr.Zero) + { + return null; + } + else + { + Bitmap = (InteropBitmap)Imaging.CreateBitmapSourceFromMemorySection(FileMappingHandle, Width, Height, PixelFormat, stride, 0); + } return Bitmap; }