X error during GLX initialization

I’m getting the folowing error during XCreateWindow

X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  1 (X_CreateWindow)
  Serial number of failed request:  13
  Current serial number in output stream:  15
Locking assertion failure.  Backtrace:
#0 /usr/lib/libxcb-xlib.so.0 [0x7ff13966c97c]
#1 /usr/lib/libxcb-xlib.so.0(xcb_xlib_lock+0x15) [0x7ff13966ca15]
#2 /usr/lib/libX11.so.6 [0x7ff139c16323]
#3 /usr/lib/libX11.so.6(XESetCloseDisplay+0x3f) [0x7ff139bf9e0f]
#4 /usr/lib/libGL.so.1 [0x7ff139f54972]

I suspect the problem is the “class” argument of XCreateWindow, but I don’t know for sure. Changing class from “InputOutput” to “vi->class” causes another X error, though - vi->class is 4, but that’s not a valid class value. Could this be an Nvidia driver bug? I’m using the GLX-1.3 functions, and I know the optioins in my FBConfig are supported by my hardware.

The full code is here

This is a pretty common usage error (been there before myself). Not an NVidia bug. For background, see Beyond the Default Visual.

Try this code to create your window instead:


void createWindow()
{
  // Init X and GLX
  Win.displayed = false;
  Display *display = Win.display = XOpenDisplay( ":0.0" );
  if ( !display )
    fatal( "Cannot open X display" );

  // Set an X error handler
  XSetErrorHandler( XErrorCB );

  int    screen   = DefaultScreen( display );
  Window root_win = RootWindow( display, screen );

  if ( !glXQueryExtension( display, 0, 0 ) )
    fatal( "X Server doesn't support GLX extension" );

  // Pick a visual
  XVisualInfo *visinfo = chooseVisual( display );
  if ( visinfo == 0 )
    fatal( "glXChooseVisual failed" );

  // Describe the visual
  printf( "Window Visual 0x%.2x", unsigned( visinfo->visualid ) );

  // Create the X window
  XSetWindowAttributes winAttr ;

  winAttr.event_mask = StructureNotifyMask | KeyPressMask ;
  winAttr.background_pixmap = None ;
  winAttr.background_pixel  = 0    ;
  winAttr.border_pixel      = 0    ;

  winAttr.colormap = XCreateColormap( display, root_win,
                                      visinfo->visual, AllocNone );
  
  unsigned int mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;

  Window win = Win.win = XCreateWindow ( display, root_win, 
                                         WIN_XPOS, WIN_YPOS, 
                                         WIN_XRES, WIN_YRES, 0, 
                                         visinfo->depth, InputOutput, 
                                         visinfo->visual, mask, &winAttr ) ;

  XStoreName( Win.display, win, "My Test");

  // Create and OpenGL context and attach to our X window
  GLXContext context = glXCreateContext( display, visinfo, NULL, 1 ) ;

  if ( ! glXMakeCurrent( display, win, context ) )
    fatal( "glXMakeCurrent failed." );

  if ( ! glXIsDirect ( display, glXGetCurrentContext() ) )
    fatal( "Indirect GLX rendering context obtained" );

  // Display the window
  XMapWindow( display, win );

  if ( ! glXMakeCurrent( display, win, context ) )
    fatal( "glXMakeCurrent failed." );

  if ( glGetError() != GL_NO_ERROR )
    fatal( "GL error in createWindow()" );
}

Adding the colormap did the trick, thanks =)

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.