magreenblatt wrote:You should not call CefShutdown in response to OnBeforeClose. Instead, CefShutdown should be called after the message loop has terminated and before the application exits (for example, at the end of your main() function). If you're using CefRunMessageLoop you should call CefQuitMessageLoop from OnBeforeClose to exit the message loop.
I'm afraid that I cannot get that far before a crash deep inside NSAutoreleasePool internals. If I instead just try to quit the app, planning to issue the CefShutdown later, the following crash occurs:
- Code: Select all
* thread #1: tid = 0x273abb, 0x9a7d645a libobjc.A.dylib`(anonymous namespace)::AutoreleasePoolPage::pop(void*) + 466, name = 'CrBrowserMain, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=2, address=0x10)
frame #0: 0x9a7d645a libobjc.A.dylib`(anonymous namespace)::AutoreleasePoolPage::pop(void*) + 466
frame #1: 0x95495cdf CoreFoundation`_CFAutoreleasePoolPop + 47
frame #2: 0x93f40934 Foundation`-[NSAutoreleasePool drain] + 122
frame #3: 0x010b74b3 libcef.dylib`base::mac::ScopedNSAutoreleasePool::~ScopedNSAutoreleasePool() [inlined] base::mac::ScopedNSAutoreleasePool::~ScopedNSAutoreleasePool(this=<unavailable>) + 35 at scoped_nsautorelease_pool.mm:20
frame #4: 0x010b749f libcef.dylib`base::mac::ScopedNSAutoreleasePool::~ScopedNSAutoreleasePool(this=0x0767e820) + 15 at scoped_nsautorelease_pool.mm:19
frame #5: 0x035112ea libcef.dylib`content::ContentMainRunnerImpl::Shutdown() [inlined] base::DefaultDeleter<base::mac::ScopedNSAutoreleasePool>::operator(ptr=0x0767e820)(base::mac::ScopedNSAutoreleasePool*) const + 8 at scoped_ptr.h:137
frame #6: 0x035112e2 libcef.dylib`content::ContentMainRunnerImpl::Shutdown() [inlined] base::internal::scoped_ptr_impl<base::mac::ScopedNSAutoreleasePool, base::DefaultDeleter<base::mac::ScopedNSAutoreleasePool> >::reset(base::mac::ScopedNSAutoreleasePool*) + 14 at scoped_ptr.h:246
frame #7: 0x035112d4 libcef.dylib`content::ContentMainRunnerImpl::Shutdown() [inlined] scoped_ptr<base::mac::ScopedNSAutoreleasePool, base::DefaultDeleter<base::mac::ScopedNSAutoreleasePool> >::reset(base::mac::ScopedNSAutoreleasePool*) at scoped_ptr.h:367
frame #8: 0x035112d4 libcef.dylib`content::ContentMainRunnerImpl::Shutdown(this=0x07678d60) + 388 at content_main_runner.cc:804
frame #9: 0x00fc99d9 libcef.dylib`CefContext::Shutdown() [inlined] CefContext::FinalizeShutdown(this=0x07678ba0) + 50 at context.cc:384
frame #10: 0x00fc99a7 libcef.dylib`CefContext::Shutdown(this=0x07678ba0) + 519 at context.cc:310
frame #11: 0x00fc8c4d libcef.dylib`(anonymous namespace)::CefForceShutdown::~CefForceShutdown() [inlined] (anonymous namespace)::CefForceShutdown::~CefForceShutdown() + 26 at context.cc:51
frame #12: 0x00fc8c33 libcef.dylib`(anonymous namespace)::CefForceShutdown::~CefForceShutdown(this=0x0489d6d8) + 3 at context.cc:49
frame #13: 0x97468faf libsystem_c.dylib`__cxa_finalize + 183
frame #14: 0x974692da libsystem_c.dylib`exit + 31
frame #15: 0x96a4c34b AppKit`-[NSApplication terminate:] + 2806
frame #16: 0x000a7924 Centerstage`-[AppImplCocoaBasic quit](self=0x072b27c0, _cmd=0x00687e10) + 100 at AppImplCocoaBasic.mm:337
frame #17: 0x000bf4bd Centerstage`cinder::app::AppBasic::quit(this=0x070a4610) + 45 at AppBasic.cpp:273
frame #18: 0x0006bf6c Centerstage`cstage::WebEngine::shutdown(this=0x07678b00) + 988 at WebEngine.cpp:198
frame #19: 0x000365d6 Centerstage`cstage::CefClientImpl::OnBeforeClose(this=0x07678920, browser=0xbfffbb80) + 1702 at CefClientImpl.cpp:80
frame #20: 0x000366a9 Centerstage`_ZThn20_N6cstage13CefClientImpl13OnBeforeCloseE9CefRefPtrI10CefBrowserE(this=0x07678934, browser=<unavailable>) + 57 at CefClientImpl.cpp:82
frame #21: 0x005e36c2 Centerstage`life_span_handler_on_before_close(self=0x07080728, browser=0x07086308) + 338 at life_span_handler_cpptoc.cc:191
frame #22: 0x00f7c08f libcef.dylib`CefLifeSpanHandlerCToCpp::OnBeforeClose(this=<unavailable>, browser=<unavailable>) + 239 at life_span_handler_ctocpp.cc:147
frame #23: 0x00fabe80 libcef.dylib`CefBrowserHostImpl::DestroyBrowser(this=0x06a90400) + 240 at browser_host_impl.cc:1201
frame #24: 0x00faeacf libcef.dylib`CefBrowserHostImpl::CloseContents(this=0x06a90400, source=0x06a8c200) + 271 at browser_host_impl.cc:1611
frame #25: 0x00fa818a libcef.dylib`CefBrowserHostImpl::CloseBrowser(this=<unavailable>, force_close=<unavailable>) + 378 at browser_host_impl.cc:539
frame #26: 0x00f5d0f3 libcef.dylib`browser_host_close_browser(self=<unavailable>, force_close=0) + 179 at browser_host_cpptoc.cc:136
frame #27: 0x005b0fb7 Centerstage`CefBrowserHostCToCpp::CloseBrowser(this=0x070867f0, force_close=false) + 135 at browser_host_ctocpp.cc:96
frame #28: 0x0006bace Centerstage`cstage::WebEngine::shouldQuit(this=0x07678b00) + 2350 at WebEngine.cpp:180
....
If I
don't issue a manual shutdown ( essentially a [NSApp terminate:nil] on mac), then my main window closes but the application hangs.
There is an odd note above CefLifeSpanHandler::DoClose which I don't understand:
// 7. CEF sends an OS close notification.
So CEF tries to shut down the application at a system level? I don't believe this is happening, but even if it is, this would make it very awkward to use CEF in conjunction with any other framework (such as ours, cinder) which already tries to handle this. Likewise, having to override the main() function is in the similar boat; ideally a user should not have to modify their main function in order to add a WebView to their application.
Anywho, do you have any idea what the autorelease pool is choking on? This is seeming to be a problem for more than just myself amongst people trying to see if CEF is a viable option for intergrating web content into an existing graphics framework.
cheers,
Rich