diff --git a/CefSharp.OffScreen/DefaultRenderHandler.cs b/CefSharp.OffScreen/DefaultRenderHandler.cs index 0de95d32a1..791938c090 100644 --- a/CefSharp.OffScreen/DefaultRenderHandler.cs +++ b/CefSharp.OffScreen/DefaultRenderHandler.cs @@ -98,7 +98,14 @@ public void Dispose() /// Return null if no screenInfo structure is provided. public virtual ScreenInfo? GetScreenInfo() { - var screenInfo = new ScreenInfo { DeviceScaleFactor = browser.DeviceScaleFactor }; + var deviceScaleFactor = browser?.DeviceScaleFactor; + + if (deviceScaleFactor == null) + { + return null; + } + + var screenInfo = new ScreenInfo { DeviceScaleFactor = deviceScaleFactor.Value }; return screenInfo; } @@ -111,9 +118,14 @@ public void Dispose() public virtual Rect GetViewRect() { //TODO: See if this can be refactored and remove browser reference - var size = browser.Size; + var size = browser?.Size; + + if (size == null) + { + return new Rect(0, 0, 1, 1); + } - var viewRect = new Rect(0, 0, size.Width, size.Height); + var viewRect = new Rect(0, 0, size.Value.Width, size.Value.Height); return viewRect; }