Skip to content

Commit 16f3bc4

Browse files
committed
When trying to get browser from frame, occasionally a null pointer was occurring as per #493.
Cleanup logic to handle null pointer, also simplify as was a little convoluted.
1 parent 48525ad commit 16f3bc4

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

CefSharp.Core/ManagedCefBrowserAdapter.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,18 +429,25 @@ namespace CefSharp
429429

430430
Task<JavascriptResponse^>^ EvaluateScriptAsync(String^ script, Nullable<TimeSpan> timeout)
431431
{
432-
auto frame = _renderClientAdapter->TryGetCefMainFrame();
433-
auto browser = frame->GetBrowser();
432+
if (timeout.HasValue && timeout.Value.TotalMilliseconds > UInt32::MaxValue)
433+
{
434+
throw gcnew ArgumentOutOfRangeException("timeout", "Timeout greater than Maximum allowable value of " + UInt32::MaxValue);
435+
}
436+
437+
auto browser = _renderClientAdapter->GetCefBrowser();
438+
434439

435-
if (_browserProcessServiceHost == nullptr && frame == nullptr)
440+
if (_browserProcessServiceHost == nullptr && browser == nullptr)
436441
{
437442
return nullptr;
438443
}
439444

440-
if(timeout.HasValue && timeout.Value.TotalMilliseconds > UInt32::MaxValue)
445+
auto frame = browser->GetMainFrame();
446+
447+
if (frame == nullptr)
441448
{
442-
throw gcnew ArgumentOutOfRangeException("timeout", "Timeout greater than Maximum allowable value of " + UInt32::MaxValue);
443-
}
449+
return nullptr;
450+
}
444451

445452
return _browserProcessServiceHost->EvaluateScriptAsync(browser->GetIdentifier(), frame->GetIdentifier(), script, timeout);
446453
}

0 commit comments

Comments
 (0)