EXC_BAD_ACCESS in 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.

EXC_BAD_ACCESS in CefShutdown

Postby richeakin » Sun Jan 12, 2014 8:24 am

Hello again,

I'm making a fair amount of progress integrating CEF3 into the cinder framework, but I've been racking my brain trying to solve an EXC_BAD_ACCESS during CefShutdown(), using cef_binary_3.1547.1412_macosx32. I was able to follow what cefclient does for a while, but I couldn't do the same for the message loop, I need to use CefDoMessageLoopWork() during cinder's App::update() instead.

I'm a bit out of hints as to what it can be, but I'll list what I know. Here is the relavant stacktrace:

Code: Select all
* thread #1: tid = 0x81f482, 0x9710545a 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: 0x9710545a libobjc.A.dylib`(anonymous namespace)::AutoreleasePoolPage::pop(void*) + 466
    frame #1: 0x92eb4cdf CoreFoundation`_CFAutoreleasePoolPop + 47
    frame #2: 0x9084d934 Foundation`-[NSAutoreleasePool drain] + 122
    frame #3: 0x02cfefa8 libcef.dylib`base::mac::ScopedNSAutoreleasePool::~ScopedNSAutoreleasePool() + 56
    frame #4: 0x02cfef4b libcef.dylib`base::mac::ScopedNSAutoreleasePool::~ScopedNSAutoreleasePool() + 43
    frame #5: 0x072df5b4 libcef.dylib`base::DefaultDeleter<base::mac::ScopedNSAutoreleasePool>::operator()(base::mac::ScopedNSAutoreleasePool*) const + 68
    frame #6: 0x072df53a libcef.dylib`base::internal::scoped_ptr_impl<base::mac::ScopedNSAutoreleasePool, base::DefaultDeleter<base::mac::ScopedNSAutoreleasePool> >::reset(base::mac::ScopedNSAutoreleasePool*) + 122
    frame #7: 0x072df319 libcef.dylib`scoped_ptr<base::mac::ScopedNSAutoreleasePool, base::DefaultDeleter<base::mac::ScopedNSAutoreleasePool> >::reset(base::mac::ScopedNSAutoreleasePool*) + 57
    frame #8: 0x072df27b libcef.dylib`content::ContentMainRunnerImpl::Shutdown() + 715
    frame #9: 0x0717027d libcef.dylib`CefContext::FinalizeShutdown() + 125
    frame #10: 0x0716f444 libcef.dylib`CefContext::Shutdown() + 676
    frame #11: 0x0716f0d1 libcef.dylib`CefShutdown() + 561
    frame #12: 0x00e646c8 libcef.dylib`cef_shutdown + 40
  * frame #13: 0x0053cab4 CinderCefTest`CefShutdown() + 36 at libcef_dll_wrapper.cc:164
    frame #14: 0x00018cb0 CinderCefTest`cstage::WebEngine::shutdown(this=0x1358dbd0) + 48 at WebEngine.cpp:340


Profiling with NSZombies didn't reveal anything, so I think it has to do with memory management on my end, however my CefApp / CefClient impl is implementing CEF's automatic reference counting, so I don't know.

I saw the order of steps listed in CefLifeSpanHandler::DoClose() and I am trying my best to adhere to the recommended method: When the app signals a shouldClose(), I close the main (and only) CefBrowser and return false to cancel. I notice DoClose being called, and I also call GetHost()->ParentWindowWillClose(). Finally, with no windows left open in my application, I close it from the menu and I still receive the same crash traced above.

Only other thing I can note is that if I don't call CefShutdown() at all, I receive a similar crash that leads back to an exc_bad_access from AutioreleasePoolPage::pop() on something named 'CrBrowserMain'.

Any suggestions to fix or further debug this are much appreciated, and thanks to those responsible for this framework!

cheers,
Rich
richeakin
Techie
 
Posts: 21
Joined: Mon Dec 16, 2013 11:50 pm

Re: EXC_BAD_ACCESS in CefShutdown

Postby magreenblatt » Sun Jan 12, 2014 1:38 pm

We don't test CefDoMessageLoopWork on Mac. Can you modify cefclient to use that function instead of CefRunMessageLoop and see what happens?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: EXC_BAD_ACCESS in CefShutdown

Postby richeakin » Sun Jan 12, 2014 8:34 pm

Thanks for the suggestion Marshall,

Hm, I was able to hack an NSTimer in there that called CefRunMessageLoop, and then control the app lifetime with [[ClientApplication sharedApplication] run]; and / [NSApp terminate:nil]; ... and it shuts down without problems. So I suppose I'm causing a stale pointer to a browser somehow, but I can't see anything yet that I'm doing differently.

One thing I noticed that I don't understand: after a should quit message occurs, I close all browser windows (which is just one), and then trigger a final CefShutdown() method. From within this call, another OnBeforeClose(CefRefPtr<CefBrowser> browser) callback is fired, although I don't have any more browser windows. What browser is this? It also occurs in the cefclient test app.
richeakin
Techie
 
Posts: 21
Joined: Mon Dec 16, 2013 11:50 pm

Re: EXC_BAD_ACCESS in CefShutdown

Postby philip142au » Fri Jun 13, 2014 5:52 am

Hi RIch,

Were you able to get CEF to run within Cinder framework?

I'm trying to do so and failing with the same error.

Philip
philip142au
Techie
 
Posts: 19
Joined: Mon Feb 03, 2014 11:26 pm

Re: EXC_BAD_ACCESS in CefShutdown

Postby richeakin » Sat Jun 14, 2014 12:35 am

I'm afraid not. See this post for more attempted fixes:

viewtopic.php?f=6&t=11441

My current understanding of the situation is that CEF just isn't built or tested to let other frameworks run the event loop - it has some basic functionality to suppor this but it isn't production ready. I'd love to see this change and will keep an eye out for it, but for now I've moved on.

Best,
Rich
richeakin
Techie
 
Posts: 21
Joined: Mon Dec 16, 2013 11:50 pm


Return to Support Forum

Who is online

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