Cef crashes on initialize OR when shutting down ...

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.

Cef crashes on initialize OR when shutting down ...

Postby octavian » Mon Aug 27, 2018 3:45 pm

- I built Cef (from source code in branch 3396) . i got both Debug & release versions.
- I built our app which uses Cef

I ran the following test:
a- start app, do some activity, close app (if is in Debug mode, the app crashes here)
b- start up, so some activity, close app. restart app (if is in release, the app crashes here)

- In case 'a' , because I have debug information, i run from gdb, so when i get crash i run 'backtrace full' so i can see full stacktrace, which is show below (triggered from CefShutdown).
- In case 'b' , because I don't have debug info loaded in the binary, i rely on whatever i print through the cef log and the last logs
are shown as coming from method: OnBeforeCommandLineProcessing() which is called on our CefApp instance.
NOTE: this particular method is triggered as a result from our app calling: CefInitialize()

Note that in this method we set the following options:
- "enable-media-stream"
- "disable-application-cache"
- "disable-cache"
- "use-fake-device-for-media-stream"
- "use-fake-ui-for-media-stream"

I also set "disable-extensions" as I earlier saw in some posts that this seem to solve a known CefShutdown() issue, but no luck, crash still occurs.

Also, when we call CefInitialize() we set the following:

- command_line_args_disabled = true
- multi_threaded_message_loop = false
- external_message_pump = true
- ignore_certificate_errors = true

What am i missing ?
Thank you!

---- trace from gdb -------Thread 1 "wfica" received signal SIGABRT, Aborted.
0xb7fdd424 in __kernel_vsyscall ()
(gdb) backtrace full
#0 0xb7fdd424 in __kernel_vsyscall ()
No symbol table info available.
#1 0xb73f1366 in raise () from /lib/i386-linux-gnu/i686/cmov/libc.so.6
No symbol table info available.
#2 0xb73f2a23 in abort () from /lib/i386-linux-gnu/i686/cmov/libc.so.6
No symbol table info available.
#3 0x9fb8af19 in base::debug::BreakDebugger() () at ../../base/debug/debugger_posix.cc:258
No locals.
#4 0x9fbade06 in ~LogMessage () at ../../base/logging.cc:855
No locals.
#5 0x9f9bdfdb in operator<<<std::__1::char_traits<char> > () at ../../buildtools/third_party/libc++/trunk/include/ostream:864
No locals.
#6 CefQuitMessageLoop () at ../../cef/libcef/browser/context.cc:296
No locals.
#7 0x9cf925cb in cef_quit_message_loop () at ../../cef/libcef_dll/libcef_dll.cc:422
No locals.
#8 0xa78d7506 in CefQuitMessageLoop () at /home/elux/Downloads/VDI-Experiments/ica_linux_driver/libcef_dll/wrapper/libcef_dll_wrapper.cc:413
No locals.
#9 0xa789266a in SimpleHandler::OnBeforeClose (this=0x8888f68, browser=...)
at /home/elux/Downloads/VDI-Experiments/ica_linux_driver/src/rtc/simple_handler.cc:205
bit = {_M_node = 0x88babc0}
#10 0xa78fa2c6 in (anonymous namespace)::life_span_handler_on_before_close (self=0x8909398, browser=0x8905a68)
at /home/elux/Downloads/VDI-Experiments/ica_linux_driver/libcef_dll/cpptoc/life_span_handler_cpptoc.cc:178
No locals.
#11 0x9cfe478e in OnBeforeClose () at ../../cef/libcef_dll/ctocpp/life_span_handler_ctocpp.cc:134
No locals.
#12 0x9f996851 in DestroyBrowser () at ../../cef/libcef/browser/browser_host_impl.cc:1519
No locals.
#13 0x9f9ad08d in DestroyAllBrowsers () at ../../cef/libcef/browser/browser_info_manager.cc:345
No locals.
#14 0x9f9be34b in FinishShutdownOnUIThread () at ../../cef/libcef/browser/context.cc:520
No locals.
#15 0x9f9bdd80 in Shutdown () at ../../cef/libcef/browser/context.cc:437
No locals.
#16 0x9f9bdb9d in CefShutdown () at ../../cef/libcef/browser/context.cc:254
No locals.
---Type <return> to continue, or q <return> to quit---
#17 0x9cf9007f in cef_shutdown () at ../../cef/libcef_dll/libcef_dll.cc:240
No locals.
#18 0xa78d18f4 in CefShutdown () at /home/elux/Downloads/VDI-Experiments/ica_linux_driver/libcef_dll/wrapper/libcef_dll_wrapper.cc:231
octavian
Techie
 
Posts: 36
Joined: Thu Jul 19, 2018 9:35 am

Re: Cef crashes on initialize OR when shutting down ...

Postby magreenblatt » Mon Aug 27, 2018 4:04 pm

You need to wait for OnBeforeClose from all browsers before calling CefShutdown. Also don't call CefQuitMessageLoop when using CefDoMessageLoopWork.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Cef crashes on initialize OR when shutting down ...

Postby octavian » Tue Aug 28, 2018 1:08 pm

Ok those suggestions helped me a lot in the sense that I no longer get a crash.

I have one thing left which I don't understand.

In my class that extends: CefClient, CefDisplayHandler, CefLifeSpanHandler & CefLoadHandler
I call this method to close existing browser instances:

void SimpleHandler::CloseAllBrowsers(bool force_close) {
if (!CefCurrentlyOn(TID_UI)) {
LOG(INFO) << "SimpleHandler::CloseAllBrowsers(): We're not currently on UI thread ..";

CEF_REQUIRE_UI_THREAD();

LOG(INFO) << "SimpleHandler::CloseAllBrowsers(): Closing browsers...";
// Execute on the UI thread.
CefPostTask(TID_UI, base::Bind(&SimpleHandler::CloseAllBrowsers, this,
force_close));
return;
}

if (browser_list_.empty()) {
LOG(INFO) << "SimpleHandler::CloseAllBrowsers(): Broswer list is empty. Nothing to do";
return;
}

BrowserList::const_iterator it = browser_list_.begin();
for (; it != browser_list_.end(); ++it) {
LOG(INFO) << "SimpleHandler::CloseAllBrowsers(): Closing one browser instance...";
(*it)->GetHost()->CloseBrowser(force_close);
}
}

The log shows that indeed
(*it)->GetHost()->CloseBrowser(force_close)
gets closed with param: true

However it does not seem to really close the browser.
I keep accumulating browser instances in browser_list_ member.

And the reason is because this callback method (on the same class) is supposed to be triggered but is never called:

void SimpleHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
LOG(INFO) << "SimpleHandler::OnBeforeClose(): start";

CEF_REQUIRE_UI_THREAD();

// Remove from the list of existing browsers.
BrowserList::iterator bit = browser_list_.begin();
for (; bit != browser_list_.end(); ++bit) {
if ((*bit)->IsSame(browser)) {
browser_list_.erase(bit);
break;
}
}
}

Where am I wrong ?
octavian
Techie
 
Posts: 36
Joined: Thu Jul 19, 2018 9:35 am

Re: Cef crashes on initialize OR when shutting down ...

Postby octavian » Tue Aug 28, 2018 1:43 pm

I should also mentioned that in that class I have implemented : DoClose() which just returns: false
as recommended in

apidocs3/projects/(default)/CefLifeSpanHandler.html#DoClose(CefRefPtr%3CCefBrowser%3E)

DoClose() is indeed called, but OnBeforeClose() is not.
octavian
Techie
 
Posts: 36
Joined: Thu Jul 19, 2018 9:35 am

Re: Cef crashes on initialize OR when shutting down ...

Postby magreenblatt » Tue Aug 28, 2018 2:49 pm

Take a look at the examples in the DoClose documentation. Make sure your application is implementing the callbacks as described.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Cef crashes on initialize OR when shutting down ...

Postby octavian » Wed Aug 29, 2018 7:41 am

yes, I read it. In DoCLose() there are two execution flows presented. they both involve user manually be involved in the aproval or canceling of the close (using a pop-up dialog I presume).
I don't want any user interaction, because I want to always close Browser when a callback is called as a result from my electron app being closed.

When I know electron app is closing , I call:
CefPostTask(TID_UI, base::Bind(&SimpleApp::closeAllBrowserWindow, app));

SimpleApp just delegates to SimpleHandler.
So what I do is in SimpleHandler I maintain the list of outstanding browser objects, and when call back is invoked, I do:

void SimpleHandler::CloseAllBrowsers(bool force_close) { // force_close is: true
....
BrowserList::const_iterator it = browser_list_.begin();
for (; it != browser_list_.end(); ++it) {
LOG(INFO) << "SimpleHandler::CloseAllBrowsers(): Closing one browser instance...";
(*it)->GetHost()->CloseBrowser(force_close);
}

This calls :
bool SimpleHandler::DoClose(CefRefPtr<CefBrowser> browser) {
LOG(INFO) << "SimpleHandler::DoClose(): start";
return false;
}

.. but it fails to call this method where i want to erase the browser instance:

void SimpleHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
LOG(INFO) << "SimpleHandler::OnBeforeClose(): start";
CEF_REQUIRE_UI_THREAD();

// Remove from the list of existing browsers.
BrowserList::iterator bit = browser_list_.begin();
for (; bit != browser_list_.end(); ++bit) {
LOG(INFO) << "SimpleHandler::OnBeforeClose(): checking one browser instance...";
if ((*bit)->IsSame(browser)) {
LOG(INFO) << "SimpleHandler::OnBeforeClose(): erasing it from list...";
browser_list_.erase(bit);
break;
}
}
}
octavian
Techie
 
Posts: 36
Joined: Thu Jul 19, 2018 9:35 am

Re: Cef crashes on initialize OR when shutting down ...

Postby magreenblatt » Wed Aug 29, 2018 11:32 am

If you don't want to close the parent window use DestroyWindow(browser->GetHost()->GetWindowHandle()) instead.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Cef crashes on initialize OR when shutting down ...

Postby octavian » Wed Sep 12, 2018 3:22 pm

I just realized: DestroyWindow is an API used in windows (by including header: windows.h)
But my code needs to build in Linux.

What s the equivalent API to:

DestroyWindow(<window handle>)

for Linux ?

Thank you,
octavian
Techie
 
Posts: 36
Joined: Thu Jul 19, 2018 9:35 am

Re: Cef crashes on initialize OR when shutting down ...

Postby octavian » Thu Sep 13, 2018 8:13 am

I should mention that browser window lives inside an X11 window.
Thus, X11 window is parent to Cef Browser window.

Source code is like this:
CefWindowInfo window_info;
CefRect windowSize(0,0, width, height);

window_info.SetAsChild(parent_id, windowSize); // where parent id is the X11 window handle

// and now I create Cef Browser window
CefBrowserHost::CreateBrowser(window_info, <cef client>, url, browser_settings, NULL);

When app is closed, I do destroy the X11 parent window, but he Cef browser window stays unfortunately.
octavian
Techie
 
Posts: 36
Joined: Thu Jul 19, 2018 9:35 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 50 guests