Search code examples
c++cx11cairoxlib

Invalid X11-Window-ID if I want to close a Window I opened before. (C/C++)


I have a problem with X11. I created a normal Window and when I click onto a button I want to open a subwindow and draw something on it using cairo.

This is how I create the window:

printf("createCairoSurface called\n");
printf("Window created: %i\n", (int)appWindow);
cairo_surface_t* new_surface = cairo_xlib_surface_create(display, appWindow, DefaultVisual(display, 0), width, height);

Before these few lines of code I create a normal window with XCreateWindow and change a few properties so my window is positioned like a panel.

But when I try to close/destroy the window with the following code the application crashes and I get the BadWindow error.

Window window = (Window)static_cast(cairo_xlib_surface_get_drawable(surface));
printf("Tried to destroy window: %i\n", (int)window);
XDestroyWindow(display, window);
X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  20 (X_GetProperty)
  Resource id in failed request:  0x240000f
  Serial number of failed request:  344
  Current serial number in output stream:  344

Even so the printf-calls I added tell me that the window id should be valid:

Window created: 37748751
Tried to destroy window: 37748751

Thank's!


Solution

  • The error is related to request X_GetProperty eg. XGetProperty.

    Your error is not coming from the XDestroyWindow() call, but for later use of the Window by your application.