OnContextCreated - GetMainFrame() is nullptr with CEF 79

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

OnContextCreated - GetMainFrame() is nullptr with CEF 79

Postby Astaroth » Thu Jan 16, 2020 6:01 pm

I'm trying to navigate to a html file and the HTTP request for an html was dying in CefLoadHandler::OnLoadError() with ERR_FAILED.

The problem was a crash here due to pBrowser->GetMainFrame() being null.

void CMyCefRenderProcessHandler::OnContextCreated(
CefRefPtr<CefBrowser> pBrowser,
CefRefPtr<CefFrame> pFrame,
CefRefPtr<CefV8Context> pContext) /*override*/
{
CEF_REQUIRE_RENDERER_THREAD();
pBrowser->GetMainFrame()->GetURL();
}

Adding an if (pBrowser->GetMainFrame()) check before the GetURL() call fixes the problem.

Is it a bug that the main frame can be null here? Or is it expected?
I never saw this with CEF 77. BTW, I'm using Windows 10 x64.
Last edited by Astaroth on Thu Jan 16, 2020 6:21 pm, edited 1 time in total.
Astaroth
Techie
 
Posts: 35
Joined: Tue Apr 23, 2019 6:23 pm

Re: OnContextCreated - GetMainFrame() is nullptr with CEF 79

Postby Astaroth » Thu Jan 16, 2020 6:16 pm

This could be a documentation bug because the comments say the function returns a frame, and don't say anything about returning nullptr

///
// Returns the main (top-level) frame for the browser window.
///
/*--cef()--*/
virtual CefRefPtr<CefFrame> GetMainFrame() = 0;
Astaroth
Techie
 
Posts: 35
Joined: Tue Apr 23, 2019 6:23 pm

Re: OnContextCreated - GetMainFrame() is nullptr with CEF 79

Postby Czarek » Thu Jan 16, 2020 7:03 pm

Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: OnContextCreated - GetMainFrame() is nullptr with CEF 79

Postby magreenblatt » Fri Jan 17, 2020 3:16 am

Please add a bug.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 67 guests