Closing the Browser Window does not call OnBeforeClose()

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.

Re: Closing the Browser Window does not call OnBeforeClose()

Postby Drakulix » Thu Apr 10, 2014 1:20 pm

magreenblatt wrote:Shutdown on OS X is a mess (in my opinion) and I'm not sure there's a way to escape platform-specific code. I updated the cefclient/cefsimple examples recently to more correctly match the Chromium shutdown process and added some related comments in https://code.google.com/p/chromiumembed ... il?id=1203.


That looks so broken :D

Okay I am actually not using Cocoa, but ObjFW (https://github.com/Midar/objfw), which makes getting this right even more difficult. (I want to make a cross-platform ObjC app and I wanted to use a WebInterface to avoid frameworks like Qt or WxWidgets. Now the Cocoa-RunLoop gets again in the way...)

So what cefsimple is doing is overriding [NSApplication terminate];
Why is that important? Only for the Menu call? Or does that also gets called when you quit it from the Dock?
Anyway, thats not too important for the actual shutdown.

So whats happening then, if I understand that correctly, is that all Browsers are closed.
Already implemented that.

Then I should call cef_quit_message_loop and cef_shutdown from the on_before_close callback of the last browser window? I am currently doing that from the on_close callback, which causes a leak. I guess I need to move that?

Also ObjFW powers it's own runloop, but thats unimportant, if I call cef_shutdown, before exit() gets called by ObjFW, right?
Or is it a must, that the main function returns?

EDIT: Okay I moved the cef_shutdown call to the last browsers on_before_close() call and now get an Invalid Context Exception inside cef_shutdown.... :|
Drakulix
Newbie
 
Posts: 9
Joined: Sat Apr 05, 2014 4:04 pm

Re: Closing the Browser Window does not call OnBeforeClose()

Postby magreenblatt » Thu Apr 10, 2014 1:36 pm

Drakulix wrote:Okay I am actually not using Cocoa, but ObjFW (https://github.com/Midar/objfw), which makes getting this right even more difficult. (I want to make a cross-platform ObjC app and I wanted to use a WebInterface to avoid frameworks like Qt or WxWidgets. Now the Cocoa-RunLoop gets again in the way...)

At a minimum you need to implement the CefAppProtocol. It may be possible to work around the Cocoa shutdown requirements (terminate:, etc) but I'm not really sure. I've had trouble in apps that didn't follow the pattern demonstrated by cefclient/cefsimple. Maybe you'll have better luck :).

Drakulix wrote:So what cefsimple is doing is overriding [NSApplication terminate];
Why is that important? Only for the Menu call? Or does that also gets called when you quit it from the Dock?

It's described in the comment here: https://code.google.com/p/chromiumembed ... _mac.mm#40

Drakulix wrote:Then I should call cef_quit_message_loop and cef_shutdown from the on_before_close callback of the last browser window?

You can call cef_quit_message_loop from inside on_before_close but don't call cef_shutdown from there. You don't want to call cef_shutdown while the CEF message loop is still running.

Drakulix wrote:I am currently doing that from the on_close callback, which causes a leak. I guess I need to move that?

Where are you finding an on_close method to override?

Drakulix wrote:Also ObjFW powers it's own runloop, but thats unimportant, if I call cef_shutdown, before exit() gets called by ObjFW, right?
Or is it a must, that the main function returns?

Yes, if you call cef_shutdown before exit() (and you've already exited the CEF run loop, and you don't hit any debug assertions) then you're probably fine.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Closing the Browser Window does not call OnBeforeClose()

Postby Drakulix » Thu Apr 10, 2014 4:39 pm

magreenblatt wrote:
Drakulix wrote:Okay I am actually not using Cocoa, but ObjFW (https://github.com/Midar/objfw), which makes getting this right even more difficult. (I want to make a cross-platform ObjC app and I wanted to use a WebInterface to avoid frameworks like Qt or WxWidgets. Now the Cocoa-RunLoop gets again in the way...)

At a minimum you need to implement the CefAppProtocol. It may be possible to work around the Cocoa shutdown requirements (terminate:, etc) but I'm not really sure. I've had trouble in apps that didn't follow the pattern demonstrated by cefclient/cefsimple. Maybe you'll have better luck :).

I have the CefAppProtocol implemented, I will look at the terminate: stuff later. But thanks.

magreenblatt wrote:
Drakulix wrote:I am currently doing that from the on_close callback, which causes a leak. I guess I need to move that?

Where are you finding an on_close method to override?

I meant do_close (life_span_handler).

magreenblatt wrote:
Drakulix wrote:Then I should call cef_quit_message_loop and cef_shutdown from the on_before_close callback of the last browser window?

You can call cef_quit_message_loop from inside on_before_close but don't call cef_shutdown from there. You don't want to call cef_shutdown while the CEF message loop is still running.

Thats it. Thanks, that crashed my app.

I also figured what caused my wired errors at start. It happens, when I release the browser struct in either on_after_create or do_close before returning. But now I get a DebugObjCt assert again on shutdown. I probably just simply miss some release-calls somewhere else. But am I not supposed to release the structs I get as arguments in any callback?
Drakulix
Newbie
 
Posts: 9
Joined: Sat Apr 05, 2014 4:04 pm

Re: Closing the Browser Window does not call OnBeforeClose()

Postby magreenblatt » Fri Apr 11, 2014 10:00 am

Drakulix wrote:But am I not supposed to release the structs I get as arguments in any callback?

See https://code.google.com/p/chromiumembed ... ingTheCAPI.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Closing the Browser Window does not call OnBeforeClose()

Postby Drakulix » Fri Apr 11, 2014 1:00 pm

magreenblatt wrote:
Drakulix wrote:But am I not supposed to release the structs I get as arguments in any callback?

See https://code.google.com/p/chromiumembed ... ingTheCAPI.


Yeah I saw that, but thanks anyway ;)
I found the bug in my code. Everything works nicely now.
Thanks for your help
Drakulix
Newbie
 
Posts: 9
Joined: Sat Apr 05, 2014 4:04 pm

Previous

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 52 guests