[SOLVED] X error in 2623 when trying to set Qt win as parent

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] X error in 2623 when trying to set Qt win as parent

Postby romariorios » Sat Feb 27, 2016 3:52 pm

Hello. I have a CEF-based project which runs a modified version of cefsimple and puts it inside a window created in another process (this is just to give some context, the details of how this is done are not relevant right now).

I'm currently running Linux and my project was based in the 2454 branch of CEF and everything was running fine, but I decided to update it directly to 2623 (in the same way I updated from 2272 to 2454). It's worth noting I made some changes to libcef which are essential to my project. However, after successfully merging bitbucket's remote 2623 branch into my 2454-based branch, the call to CefBrowserHost::CreateBrowser() fails with the following message:

Code: Select all
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  1 (X_CreateWindow)
  Serial number of failed request:  131
  Current serial number in output stream:  139


Same thing happens with CefBrowserHost::CreateBrowserSync(). I figured this could've been caused by some bad conflict resolution, but I tried to open cefclient to see if the same problem happened, but cefclient worked perfectly. I checked cefclient's CreateBrowser calls and they didn't seem very different from mine. Here's how I'm calling it by the way:

Code: Select all
  // SimpleHandler implements browser-level callbacks.
  CefRefPtr<SimpleHandler> handler(new SimpleHandler);

  // Information used when creating the native window.
  CefWindowInfo window_info;
  window_info.SetAsChild(windowId, CefRect(0, 0, size.width(), size.height()));

  // Specify CEF browser settings here.
  CefBrowserSettings browser_settings;

  // Create the first browser window.
  CefBrowserHost::CreateBrowser(window_info, handler, "",
                                browser_settings, nullptr);


windowId is the window ID from the parent window (created by the other process). This code is called when the parent process sends a message to cefsimple containing its ID. Nothing much different from cefclient aside from the IPC part.

I'm now trying to debug the code to see what parameter attributes are invalide (since X's message doesn't tell me). I'm now at the call to XCreateWindow, deep down Chromium's code, and here are the values it's being called with:

Code: Select all
Window XCreateWindow(
    Display*      /* display */,
    Window      /* parent */,
    int         /* x */,                      // 0
    int         /* y */,                      // 0
    unsigned int   /* width */,               // 800
    unsigned int   /* height */,              // 600
    unsigned int   /* border_width */,        // 0
    int         /* depth */,                  // 24
    unsigned int   /* class */,               // InputOutput (1)
    Visual*      /* visual */,                // {
                                              //   bits_per_rgb = 8;
                                              //   blue_mask = 255;
                                              //   c_class = 4;
                                              //   ext_data = 0;
                                              //   green_mask = 65280;
                                              //   map_entries = 256;
                                              //   red_mask = 16711680;
                                              //   visualid = 35
                                              // }
    unsigned long   /* valuemask */,          // 17
    XSetWindowAttributes*   /* attributes */  // {
                                              //   background_pixel = 0;
                                              //   background_pixmap = 0;
                                              //   backing_pixel = 0;
                                              //   backing_planes = 0;
                                              //   backing_store = 0;
                                              //   bit_gravity = 1;
                                              //   border_pixel = 0;
                                              //   border_pixmap = 0;
                                              //   colormap = 0;
                                              //   cursor = 0;
                                              //   do_not_propagate_mask = 0;
                                              //   event_mask = 0;
                                              //   override_redirect = 0;
                                              //   save_under = 0;
                                              //   win_gravity = 0;
                                              // }
);


I took a glimpse at the XCreateWindow docs, but all I got was:
XLib Programming Manual: XCreateWindow, XCreateSimpleWindow wrote:For class InputOutput, the visual type and depth must be a combination supported for the screen, or a BadMatch error results.

That's not very descriptive. I'm pretty sure my current setup supports 24 bits, but how should I know the type?

Anyway, that's as far as I got. I have no other clue. I tried called the Sync function, tried creating a parentless window, changing attributes, changing the CefInitialize() call, but nothing solved my problem and I still have no clue of what's causing it. Any help is appreciated.

Thanks in advance.

EDIT: The crash actually happens at a XFlush call in TouchFactory::SetupXI2ForXWindow().
Last edited by romariorios on Tue Mar 29, 2016 3:08 pm, edited 3 times in total.
romariorios
Mentor
 
Posts: 50
Joined: Thu Apr 30, 2015 6:13 am
Location: Brazil

Re: X error after merging 2623 into 2454-based project

Postby magreenblatt » Sat Feb 27, 2016 9:37 pm

Make sure you're installing the xlib error handlers at the right time. Compare your applications's main() function to the 2623 branch version of cefclient/cefsimple.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: X error after merging 2623 into 2454-based project

Postby romariorios » Sun Feb 28, 2016 7:34 pm

magreenblatt wrote:Make sure you're installing the xlib error handlers at the right time.

I installed the error handlers in the same way cefsimple does and the only thing that changed is that the process doesn't crash anymore, but the window still doesn't get shown. I never needed error handlers, though.

magreenblatt wrote:Compare your applications's main() function to the 2623 branch version of cefclient/cefsimple.

Here's my main, for reference:
Code: Select all
// Entry point function for all processes.
int main(int argc, char* argv[]) {
  // Provide CEF with command-line arguments.
  CefMainArgs main_args(argc, argv);

  // CEF applications have multiple sub-processes (render, plugin, GPU, etc)
  // that share the same executable. This function checks the command-line and,
  // if this is a sub-process, executes the appropriate logic.
  int exit_code = CefExecuteProcess(main_args, nullptr, nullptr);
  if (exit_code >= 0) {
    // The sub-process has completed so return here.
    return exit_code;
  }

  const char *cachePath = "./cache";
  QDir(cachePath).removeRecursively();

  // SimpleApp implements application-level callbacks. It will create the first
  // browser instance in OnContextInitialized() after CEF has initialized.
  CefRefPtr<SimpleApp> app(new SimpleApp);

  QCoreApplication qtApp(argc, argv);
  QTimer cefTimer;
  QObject::connect(&cefTimer, &QTimer::timeout, CefDoMessageLoopWork);
  cefTimer.start(16);

  // Specify CEF global settings here.
  CefSettings settings;
  CefString(&settings.cache_path).FromASCII(cachePath);

  // Initialize CEF for the browser process.
  CefInitialize(main_args, settings, app, nullptr);

  int result = qtApp.exec();

  // Shut down CEF.
  CefShutdown();

  return result;
}
romariorios
Mentor
 
Posts: 50
Joined: Thu Apr 30, 2015 6:13 am
Location: Brazil

Re: X error after merging 2623 into 2454-based project

Postby magreenblatt » Mon Feb 29, 2016 3:00 pm

How are you running the CEF message loop?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: X error after merging 2623 into 2454-based project

Postby romariorios » Tue Mar 01, 2016 6:12 am

magreenblatt wrote:How are you running the CEF message loop?

I connect a 16-ms QTimer to the CefDoMessageLoopWork function and then run Qt's event loop:

Code: Select all
  QCoreApplication qtApp(argc, argv);
  QTimer cefTimer;
  QObject::connect(&cefTimer, &QTimer::timeout, CefDoMessageLoopWork);
  cefTimer.start(16);
  // ...
  int result = qtApp.exec();


I has not been a source of problems so far, though.
romariorios
Mentor
 
Posts: 50
Joined: Thu Apr 30, 2015 6:13 am
Location: Brazil

Re: X error after merging 2623 into 2454-based project

Postby romariorios » Mon Mar 07, 2016 6:18 pm

Hello.

I just re-did the merge, to guarantee I made no mistakes, and built everything from scratch, but I still get the same error. I'm running Kubuntu 14.04 64 bits, if that helps.

Any idea of possible places to look for and try to fix this? I made sure no patches were missing before recompiling CEF.

Thanks again.
romariorios
Mentor
 
Posts: 50
Joined: Thu Apr 30, 2015 6:13 am
Location: Brazil

Re: X error after merging 2623 into 2454-based project

Postby Czarek » Tue Mar 08, 2016 12:29 am

You are using "QCoreApplication qtApp(argc, argv)". From the docs:
The QCoreApplication class provides an event loop for Qt applications without UI.

Maybe this has something to do with the issue. Is CefDoMessageLoopWork() expecting to integrate into existing UI event loop? How about calling CefRunMessageLoop()? It's more performant.

Ref: http://doc.qt.io/qt-5/qcoreapplication.html
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

Re: X error after merging 2623 into 2454-based project

Postby romariorios » Tue Mar 08, 2016 8:12 am

Czarek wrote:You are using "QCoreApplication qtApp(argc, argv)". From the docs:
The QCoreApplication class provides an event loop for Qt applications without UI.

Maybe this has something to do with the issue. Is CefDoMessageLoopWork() expecting to integrate into existing UI event loop? How about calling CefRunMessageLoop()? It's more performant.

Ref: http://doc.qt.io/qt-5/qcoreapplication.html


I never use any Qt GUI classes inside cefsimple, so the usage of QCoreApplication is just fine. I need to instantiate QCoreApplication because I use many classes which depend on (a.k.a. are much convenient to use with) the event loop and I cannot run Qt's event loop and CEF's message loop at the same time.

Also, this approach has been working well so far (I've been using it for almost a year with CEF 2272 and 2454). Why would it turn into an issue now?

Thanks for the reply!
romariorios
Mentor
 
Posts: 50
Joined: Thu Apr 30, 2015 6:13 am
Location: Brazil

Re: X error after merging 2623 into 2454-based project

Postby romariorios » Tue Mar 08, 2016 6:42 pm

I just noticed another problem: it seems that the OnProcessMessageReceived method is not being called -- which means the JS bindings are not working. Should I create a new thread for this?
romariorios
Mentor
 
Posts: 50
Joined: Thu Apr 30, 2015 6:13 am
Location: Brazil

Re: X error in 2623 when trying to set Qt window as parent (

Postby romariorios » Wed Mar 09, 2016 7:03 am

I just confirmed this to be a bug in CEF 2623.

How to reproduce it:
1 - Download this simple Qt application, then build and execute it: https://www.dropbox.com/s/n6qqficr8ef6n ... ar.gz?dl=0
2 - It will print out the window ID in the console, like this:
Code: Select all
Window ID: 54525956

3 - Download both CEF 2526 and 2623
4 - Add the following line in the SimpleApp::OnContextInitialized method from the cefsimple/simple_app.cc file:
Code: Select all
  window_info.SetAsChild(54525956, CefRect(0, 0, 800, 600));

5 - Execute the cefsimple from 2526, then the one from 2623

cefsimple/2526 will put a window inside test-app's window. cefsimple/2623 will not and will print out many X errors.
romariorios
Mentor
 
Posts: 50
Joined: Thu Apr 30, 2015 6:13 am
Location: Brazil

Next

Return to Support Forum

Who is online

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