Object reference incorrectly held at CefShutdown

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.

Object reference incorrectly held at CefShutdown

Postby joeludwig » Sun Jan 12, 2020 7:41 pm

I'm getting this error/crash at shutdown:
Code: Select all
[0112/115346.263:FATAL:shutdown_checker.cc(52)] Check failed: !IsCefShutdown(). Object reference incorrectly held at CefShutdown


This seems to be a browser object that was created by a window.open call in Javascript. The open call was to a custom protocol (steam:// in this case, but I don't think it matters.) In OnProtocolExecution I call:
Code: Select all
browser->GetHost()->CloseBrowser( true );


And then return without keeping a reference to the browser. I'm pretty sure I don't have reference to the browser anywhere on my side. Yet in CefShutdown there's one browser object still hanging around with a reference to it.

Is there some stronger way to close a browser than the above? Is there some way to handle custom protocols without ever opening a window in the first place?
joeludwig
Newbie
 
Posts: 8
Joined: Wed Aug 28, 2019 12:07 am

Re: Object reference incorrectly held at CefShutdown

Postby Czarek » Mon Jan 13, 2020 5:11 am

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: Object reference incorrectly held at CefShutdown

Postby joeludwig » Mon Jan 13, 2020 2:21 pm

I saw that issue, but don't seem to have a stack track in the debug output or the log file. Is that something I have to turn on?


Joe
joeludwig
Newbie
 
Posts: 8
Joined: Wed Aug 28, 2019 12:07 am

Re: Object reference incorrectly held at CefShutdown

Postby Czarek » Mon Jan 13, 2020 2:39 pm

You have to run a debugger to print backtrace. You should download debug symbols from where you've obtained binaries.
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: Object reference incorrectly held at CefShutdown

Postby Tonygeek » Wed Jan 15, 2020 6:34 am

I have a similar problem but am unaware of what can I do to narrow it down.
I get this message:
[0115/061854.595:FATAL:browser_main.cc(215)] Check failed: global_request_context_->HasOneRef().
and this call stack:
Code: Select all
    libcef.dll!logging::LogMessage::~LogMessage() Line 950   C++
    libcef.dll!CefBrowserMainParts::PostMainMessageLoopRun() Line 216   C++
    libcef.dll!content::BrowserMainLoop::ShutdownThreadsAndCleanUp() Line 1071   C++
    libcef.dll!content::BrowserMainRunnerImpl::Shutdown() Line 179   C++
    libcef.dll!CefMainDelegate::ShutdownBrowser() Line 812   C++
    libcef.dll!CefContext::FinalizeShutdown() Line 632   C++
    libcef.dll!CefContext::Shutdown() Line 488   C++
    libcef.dll!CefShutdown() Line 272   C++
   Win32CEFSimpleApp.exe!CefShutdown() Line 121   C++
    Win32CEFSimpleApp.exe!wWinMain(HINSTANCE__ * hInstance=0x01310000, HINSTANCE__ * hPrevInstance=0x00000000, wchar_t * lpCmdLine=0x00c729c8, int nCmdShow=10) Line 93   C++


cefsimple and cefclient work fine, it is only my app that exhibits this. However the code is mostly copied from cefsimple and the main difference is in window creation ( I call CreateBrowser() from WM_CREATE).
Tonygeek
Techie
 
Posts: 16
Joined: Mon Jan 13, 2020 7:39 pm

Re: Object reference incorrectly held at CefShutdown

Postby Tonygeek » Wed Jan 15, 2020 9:48 am

Sorry, my bad.
In my case I had a member variable in my client:

Code: Select all
CefRefPtr<CefBrowser> browser;


but I forgot to null it before calling CefQuitMessageLoop().
Tonygeek
Techie
 
Posts: 16
Joined: Mon Jan 13, 2020 7:39 pm

Re: Object reference incorrectly held at CefShutdown

Postby joeludwig » Sun Jan 19, 2020 12:42 pm

Czarek wrote:You have to run a debugger to print backtrace. You should download debug symbols from where you've obtained binaries.

I have symbols (and even source) for the CEF build I'm using. I am running in the debugger.

I have a backtrace for the assert itself. That issue makes it sound like I should have a backtrace for either where the ref was incremented or where the browser was created. I don't have either of those. Is that a thing, or is trying to trace through the refs and unrefs of all browsers the best I can do?


Joe
joeludwig
Newbie
 
Posts: 8
Joined: Wed Aug 28, 2019 12:07 am

Re: Object reference incorrectly held at CefShutdown

Postby Czarek » Sun Jan 19, 2020 2:03 pm

The stack trace should point you to an object that fails. Then you have to fix usage of that object in your app.
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: Object reference incorrectly held at CefShutdown

Postby joeludwig » Sun Jan 19, 2020 3:42 pm

Czarek wrote:The stack trace should point you to an object that fails. Then you have to fix usage of that object in your app.


When you say "the stack trace", you mean the stack trace when the fatal log message is emitted at shutdown? That's the only one I've seen.

That pointed me at a browser object I didn't create that was handed to me in OnProtocolExecution, which I then kept no reference to. Here's my entire interaction with that browser object:

Code: Select all
void CAardvarkResourceRequestHandler::OnProtocolExecution( CefRefPtr<CefBrowser> browser,
   CefRefPtr<CefFrame> frame,
   CefRefPtr<CefRequest> request,
   bool& allow_os_execution )
{
   std::string url = request->GetURL();
   allow_os_execution = tools::stringIsPrefix( "pluto://", url )
      || tools::stringIsPrefix( "steam://", url )
      || tools::stringIsPrefix( "aardvark://", url );

   // we never want to keep these dead windows around
   browser->GetHost()->CloseBrowser( true );
}
joeludwig
Newbie
 
Posts: 8
Joined: Wed Aug 28, 2019 12:07 am

Re: Object reference incorrectly held at CefShutdown

Postby Czarek » Sun Jan 19, 2020 4:10 pm

Do not close browser from within callbacks. Use CefPostTaskDelayed or similar to close after the callback completes.
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


Return to Support Forum

Who is online

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