Search code examples
linuxx11xcb

Why is xcb_key_symbols_alloc returning NULL on big screens?


I am calling xcb_key_symbols_alloc in my code (which i am testing in Xephyr). If the screen is smaller (e.g. 960x540), everything works fine, but when i try it on a bigger screen (e.g. 1280x720), it suddenly starts returning NULL. It also works if i put it on my main display (where gnome is running), it suddenly starts working again.

Why is this happening and how would go about i fix it?


Solution

  • Why is this happening and how would go about i fix it?

    Let's look at the source code! Debian Codesearch found https://sources.debian.org/src/xcb-util-keysyms/0.4.0-1/keysyms/keysyms.c/?hl=74#L74

    There are three cases for this function to return NULL.

      if (!c || xcb_connection_has_error(c))
        return NULL;
    

    You are passing in a NULL pointer or a XCB connection that is already broken.

      syms = malloc (sizeof (xcb_key_symbols_t));
      if (!syms)
        return NULL;
    

    A memory allocation failure.

    If I had to guess, I would say that your XCB connection is broken / is in an error state. Since you say this is about the size of the root window, you are perhaps doing a too large PutImage request earlier?

    A random printf-debugging idea would be to put printf("I am here and state is %d\n", xcb_connection_has_error(c)) in some random places and use that to figure out where exactly the connection breaks / goes into an error state.