[SOLVED] CreateBrowser crash when integrating with wxWidgets

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.

[SOLVED] CreateBrowser crash when integrating with wxWidgets

Postby chellio » Tue Jun 21, 2016 7:04 pm

OS: Ubuntu 14.04
CEF v: cef_binary_3.2704.1410.g80c7c1b_linux64

I decide to integrate wxwidgets and CEF.
CefDoMessageLoop is runnig from wxTimer on constant intervals.
I noticed that crash occurs only when CefDoMessageLoopWork() and CefBrowserHost::CreateBrowser() are both called.
If I don't call CefDoMessageLoopWork, CefBrowserHost::CreateBrowser() doesn't crash.

The program 'CEF_wxw' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadMatch (invalid parameter attributes)'.
(Details: serial 304 error_code 8 request_code 42 minor_code 0)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the --sync command line
option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)


Main function:
Code: Select all
    CefMainArgs args(argc,argv);

    CefRefPtr<AppHandler> app = new AppHandler; //CefApp implementation

    int ret = CefExecuteProcess(args, app, NULL );
    if(ret>=0)
    {
        return ret;
    }

    //wxw
    MyApp *myapp = new MyApp;
    wxAppConsole::SetInstance(myapp);

    myapp->m_cefapp = app; // It will be passed to CefInitialize later
    myapp->m_cefargs = args;


    wxEntry(argc, argv);


Here is callback for initialization of wxWidgets:
Code: Select all
bool MyApp::OnInit()
{

    CefSettings sett;
    sett.multi_threaded_message_loop = false;
    sett.external_message_pump = true;

    CefInitialize(m_cefargs, sett, m_cefapp, NULL);

    MyFrame *myframe = new MyFrame("CEF + wxw", wxPoint(150,200), wxSize(400,200));
    myframe->Show(true);

    timer = new MyTimer;
    timer->Start(20); // On 20ms intervals CefDoMessageLoop is calling

    return true;


}


CefBrowserHost::CreateBrowser is called in response to button click. Here is callback:
Code: Select all
   
   CefWindowInfo wnd_info;
   // CefWindowHandle x_handle = gdk_x11_drawable_get_xid(gtk_widget_get_window(GetHandle())); For test I comment it
   // wnd_info.SetAsChild( x_handle, CefRect(0,0,100,100) );

    CefBrowserSettings sett;

    // CefRefPtr<ClientHandler> client = new ClientHandler(); // It no matter if I pass CefClient object or not

    CefBrowserHost::CreateBrowser(wnd_info, NULL, "http://google.com/",
                                   sett, NULL);  // Here it crash
Last edited by chellio on Fri Jun 24, 2016 7:01 am, edited 2 times in total.
chellio
Techie
 
Posts: 27
Joined: Fri May 20, 2016 9:26 am
Location: Poland

Re: CreateBrowser crash when integrating with wxWidgets

Postby magreenblatt » Wed Jun 22, 2016 10:09 am

CreateBrowser won't do anything if you don't run the message loop.

Install xlib error handlers so that the application won't be terminated on non-fatal errors. For example: https://bitbucket.org/chromiumembedded/ ... ew-default
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CreateBrowser crash when integrating with wxWidgets

Postby chellio » Wed Jun 22, 2016 10:23 am

So it must be fatal error, because I have already that stuff. (I don't paste all sources)

Ok, but I call CefDoMessageLoopWork() on timer, and then I call CreateBrowser that causes crash. Maybe my approach is totally wrong and I must try from something different...
chellio
Techie
 
Posts: 27
Joined: Fri May 20, 2016 9:26 am
Location: Poland

Re: CreateBrowser crash when integrating with wxWidgets

Postby chellio » Wed Jun 22, 2016 10:32 am

Wow, problem solved :idea: :idea: . It was caused by linking to gtk from my project. Maybe some conflict occured. I needed it to convert GtkWidget to X11 Window to properly use SetAsChild in CefWindowInfo. Now it is question how to link to gtk. wxWidgets also uses gtk.

Here is the same problem:
http://stackoverflow.com/questions/1478 ... -gtkwidget
Last edited by chellio on Wed Jun 22, 2016 11:15 am, edited 1 time in total.
chellio
Techie
 
Posts: 27
Joined: Fri May 20, 2016 9:26 am
Location: Poland

Re: CreateBrowser crash when integrating with wxWidgets

Postby magreenblatt » Wed Jun 22, 2016 10:58 am

Does wxWidgets use GTK as a shared library? Are both wxWidgets and your application linking the same version of GTK? Where/how are you managing GTK initialization?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CreateBrowser crash when integrating with wxWidgets

Postby chellio » Wed Jun 22, 2016 6:56 pm

Yes, wxWidgets always uses GTK as shared. My version uses GTK+2 and I link to it from my project.
I don't know what exactly happened but now CreateBrowser works on CefBrowserProcessHandler::OnContextInitialized.
On wxFrame callback, in response to button click it still doesn't work. But I don't need it now - so I back propably to that problem later.

For now I have trouble with mentioned gtk initialization. What is correct place to call gtk_init and gdk_init? It is needed if I only want to call:
Code: Select all
CefWindowInfo wnd_info;
CefWindowHandle x_handle = gdk_x11_drawable_get_xid(gtk_widget_get_window(Singletons::m_wxframe->GetHandle()));
wnd_info.SetAsChild( x_handle, CefRect(0,0,100,100) );

If I call gtk_init on startup, again I have errors with CefBrowserHost::CreateBrowser.
And also after creation of wxFrame CefBrowserHost::CreateBrowser fails.

It is ok to pass top-level wxFrame in such way? gtk stuff causes Segmentation fault (core dumped)..
chellio
Techie
 
Posts: 27
Joined: Fri May 20, 2016 9:26 am
Location: Poland

Re: CreateBrowser crash when integrating with wxWidgets

Postby magreenblatt » Wed Jun 22, 2016 9:25 pm

wxWidgets is probably calling gtk_init/gdk_init internally. You probably shouldn't call it multiple times in the same process.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CreateBrowser crash when integrating with wxWidgets

Postby chellio » Thu Jun 23, 2016 3:27 am

I get handle from inner wxPanel and converting it to X11 Window works fine.

Problem witch creating browser, after wxFrame creation and wx message loop runed still exist. I will try to build wxWidgets from sources. I have no other ideas.
chellio
Techie
 
Posts: 27
Joined: Fri May 20, 2016 9:26 am
Location: Poland

Re: CreateBrowser crash when integrating with wxWidgets

Postby chellio » Fri Jun 24, 2016 6:58 am

It works with wxWidgets 3.1 compiled from sources with option --with-gtk=3
chellio
Techie
 
Posts: 27
Joined: Fri May 20, 2016 9:26 am
Location: Poland


Return to Support Forum

Who is online

Users browsing this forum: delta42, Google [Bot], Majestic-12 [Bot] and 85 guests