Meteorhead

CL-GL interop segfault at init

Discussion created by Meteorhead on Jun 22, 2011
Latest reply on Jun 23, 2011 by Meteorhead
urgent!

Hi all!

I have a problem which is very urgent, so a little help would be apreciated. I am writing a rather simple CL-GL interop application, but the program crashes at init. Let me copy-paste the relevant lines of the code. Point is I do not see "GL context acquired" in the console, even if I comment out the rest of the setupCL_GL() function. It breaks at creating cpsGL[] but I do not know why.

Help would be very much apreciated!

... // OpenCL and OpenGL includes #include <GL/glew.h> #include <GL/glxew.h> #include <GL/glut.h> #include <CL/cl.h> #include <CL/cl_gl.h> // OpenCL-OpenGL variables GLint GL_err; cl_int numDevices, my_device, CL_err; cl_uint numPlatforms; cl_platform_id platform = NULL; cl_device_id* devices; cl_context_properties* cprops; cl_context context; GLXContext glCtx; ... void setupCL_GL() { // Begin platform layer std::cout << "Accessing platform layer\n"; CL_err = clGetPlatformIDs(0, NULL, &numPlatforms); checkErr(CL_err, "clGetPlatformIDs(numPlatforms)"); if (0 < numPlatforms) { cl_platform_id* platforms = new cl_platform_id[numPlatforms]; CL_err = clGetPlatformIDs(numPlatforms, platforms, NULL); checkErr(CL_err, "clGetPlatformIDs(platforms)"); for (unsigned i = 0; i < numPlatforms; ++i) { char pbuf[100]; CL_err = clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, NULL); checkErr(CL_err, "clGetPlatformInfo()"); platform = platforms[i]; if (!strcmp(pbuf, "Advanced Micro Devices, Inc.")) {break;} } delete[] platforms; } // If we could find our platform, use it. Otherwise pass a NULL and get whatever the // implementation thinks we should be using. std::cout << "Using platform: "; char vendor[64]; clGetPlatformInfo(platform, CL_PLATFORM_VENDOR, sizeof(vendor), vendor, NULL); printf(vendor); std::cout << "\n"; glCtx = glXGetCurrentContext(); cl_context_properties cpsGL[] = {CL_CONTEXT_PLATFORM, (cl_context_properties)platform, CL_GLX_DISPLAY_KHR, (intptr_t) glXGetCurrentDisplay(), CL_GL_CONTEXT_KHR, (intptr_t) glCtx, 0}; std::cout << "GL context acquired\n"; ... } int main() { setupCL_GL(); ... }

Outcomes