1 Reply Latest reply on Sep 13, 2012 5:29 AM by Meteorhead

    glXChooseFBConfig segfaults

    Meteorhead

      Hi!

       

      My problem is that I'm trying to write a code based on the multi-GPU OpenCL-OpenGL interop sample provided by the OpenCL Programming Guide in the appendix. Right now I'm only coding the device enumeration as far as OpenGL is concerned, no interop stuff yet. However, my code crashes at glXChooseFBConfig.

       

      The problem with all the samples is that sometimes they lack type definitions, but from the linux part, there are functions that don't even exist!

       

      This is the code I'm trying to run:

       

              Display* displayName = XOpenDisplay(NULL);

              int screenNumber = ScreenCount(displayName);

              XCloseDisplay(displayName);

       

              std::cout << "Number of screens: " << screenNumber << std::endl;

       

              for (int i = 0; i < screenNumber; i++)

              {

                      //if (isDeviceIdEnabled())

                      {

                              //if (i < deviceId) { continue; }

                      }

       

                      char disp[100];

                      sprintf(disp, "DISPLAY=:0.%d", i);

                      putenv(disp);

       

                      std::cout << "Opening display " << i << "...";

                      displayName = XOpenDisplay(0);

                      std::cout << "done." << std::endl;

       

                      std::cout << "Setting up window...";

                      int nelements;

                      std::cout << " choosing frame buffer config...";

                      GLXFBConfig *fbc = glXChooseFBConfig(displayName, DefaultScreen(displayName), 0, &nelements);

                      static int attributeList[] = { GLX_RGBA,

                                                      GLX_DOUBLEBUFFER,

                                                      GLX_RED_SIZE,

                                                      1,

                                                      GLX_GREEN_SIZE,

                                                      1,

                                                      GLX_BLUE_SIZE,

                                                      1,

                                                      None };

                      std::cout << " choosing visual...";

                      XVisualInfo *vi = glXChooseVisual(displayName, DefaultScreen(displayName), attributeList);

                      XSetWindowAttributes swa;

                      std::cout << " creating colormap...";

                      swa.colormap = XCreateColormap(displayName, RootWindow(displayName, vi->screen), vi->visual, AllocNone);

                      swa.border_pixel = 0;

                      swa.event_mask = StructureNotifyMask;

       

                      std::cout << "done." << std::endl;

                      std::cout << "Opening window...";

       

                      int x = 10; int y = 10; int width = 100; int height = 100;

                      ::Window win = XCreateWindow( displayName,

                                              RootWindow(displayName, vi->screen),

                                              x,

                                              y,

                                              width,

                                              height,

                                              0,

                                              vi->depth,

                                              InputOutput,

                                              vi->visual,

                                              CWBorderPixel|CWColormap|CWEventMask,

                                              &swa );

       

                      std::cout << " mapping window...";

                      XMapWindow (displayName, win);

       

                      std::cout << " creating context...";

                      int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 2, 0 };

                      GLXContext ctx = glXCreateContextAttribsARB(displayName, *fbc, 0, true, attribs);

                      std::cout << "done." << std::endl;

       

                      std::cout << "Making context current...";

                      glXMakeCurrent (displayName, win, ctx);

                      std::cout << "done." << std::endl;

       

                      std::cout << "Fetch current context...";

                      GLXContext gGlCtx = glXGetCurrentContext();

                      std::cout << "done." << std::endl;

              }

       

      I have HD5970 in my machine, I log in using SSH but issue export DISPLAY=:0 and glxinfo provides correct information with GLSL version 4.2 available. If I run the program, I only see Opening Display, but when running with valgrind, giving more time for the terminal to print it's things, I see "Choosing frame buffer config..." too among valgrind printed stuff. After that it's Segmentation fault (core dumped)

       

      I would really appreciate the help.