Multiple Cef Instance in mac

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.

Multiple Cef Instance in mac

Postby rahulchavan10 » Fri Feb 09, 2018 7:56 am

I want to run browser on click. Below mentioned "runBrowser" function is called on each click. But once any one browser is closed that cause CEF ShutDown and next time if I click on button ""runBrowser" function throws exception. I am working with CEF3 latest version on mac. Please help. Attahed Log for the same.
Any input will be greatly appreciated.



bool initialize = false;

CefRefPtr<CefClient> client = NULL;
CefRefPtr<ClientApp> app = NULL;

void runBrowser(){
if(! initialize){
CefMainArgs main_args;

// [ClientApplication sharedApplication];

app = new ClientApp(new ScriptingPbj());


int exit_code = CefExecuteProcess( main_args, app.get(), NULL );
if ( exit_code >= 0 ) {
exit(exit_code);
}

char cwd[1024];
getcwd( cwd, sizeof(cwd) );

CefSettings settings;

CefInitialize( main_args, settings, app.get(), NULL );

client = new ClientHandler();
}
initialize = true;
CefWindowInfo info;
CefBrowserSettings b_settings;

std::string path;
path = "https://www.google.com";



info.SetAsChild(NULL, 0, 0, 512, 270);
CefBrowserHost::CreateBrowser(info, client.get(), path, b_settings, NULL);

CefRunMessageLoop();
CefShutdown();
}


@implementation HandleEvents


- (IBAction)runBrowser:(id)sender
{
runBrowser();
}

@end
Attachments
log.rtf
(10.57 KiB) Downloaded 369 times
rahulchavan10
Techie
 
Posts: 29
Joined: Tue Dec 19, 2017 6:03 am

Re: Multiple Cef Instance in mac

Postby magreenblatt » Fri Feb 09, 2018 12:56 pm

Look at what your ClientHandler does in the OnBeforeClose callback.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Multiple Cef Instance in mac

Postby rahulchavan10 » Mon Feb 12, 2018 12:55 am

It only sets browser to NULL, nothing else is there.
Are you expecting some more things to be done there?
rahulchavan10
Techie
 
Posts: 29
Joined: Tue Dec 19, 2017 6:03 am

Re: Multiple Cef Instance in mac

Postby Czarek » Mon Feb 12, 2018 1:34 am

On each click you execute "runBrowser" function and that function is calling CefShutdown each time along with message loop. Message loop and shutdown should be called only once during app lifetime.
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: No registered users and 33 guests