more guarding

pull/26281/head
kallaballa 4 months ago
parent 4cbb96b396
commit 3edcf410b6
  1. 33
      modules/core/src/opengl.cpp

@ -1641,11 +1641,11 @@ Context& initializeContextFromGL()
#elif !defined(HAVE_OPENCL_OPENGL_SHARING)
NO_OPENCL_SHARING_ERROR;
#else
cl_uint platformsCnt;
cl_uint devCnt;
cl_device_id* devices;
cl_uint devUsed;
cl_context context;
cl_uint platformsCnt = 0;
cl_uint devCnt = 0;
cl_device_id* devices = nullptr;
cl_uint devUsed = 0;
cl_context context = nullptr;
cl_int status = clGetPlatformIDs(0, NULL, &platformsCnt);
if (status != CL_SUCCESS)
@ -1667,6 +1667,7 @@ Context& initializeContextFromGL()
if (status != CL_SUCCESS)
CV_Error_(cv::Error::OpenCLInitError, ("OpenCL: No devices available: %d", status));
try {
devices = new cl_device_id[devCnt];
status = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_GPU, devCnt, devices, NULL);
@ -1689,7 +1690,7 @@ Context& initializeContextFromGL()
status = clGetDeviceInfo(devices[j], CL_DEVICE_EXTENSIONS, extensionSize, extensions, &extensionSize);
if (status != CL_SUCCESS)
continue;
} catch(std::exception& ex) {
} catch(...) {
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Exception thrown during device extensions gathering");
}
@ -1721,12 +1722,17 @@ Context& initializeContextFromGL()
}
}
}
if (!sharingSupported)
} catch(...) {
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Exception thrown during device information gathering");
if(devices != nullptr) {
delete[] devices;
}
continue;
}
if (sharingSupported) {
// Define OS-specific context properties and create the OpenCL context
#if defined (__APPLE__)
#if defined (__APPLE__)
CGLContextObj cglContext = CGLGetCurrentContext();
CGLShareGroupObj cglShareGroup = CGLGetShareGroup(cglContext);
cl_context_properties props[] =
@ -1735,7 +1741,7 @@ Context& initializeContextFromGL()
0
};
context = clCreateContext(props, 0,0, NULL, NULL, &ciErrNum);
#elif defined(__ANDROID__)
#elif defined(__ANDROID__)
cl_context_properties props[] =
{
CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
@ -1744,7 +1750,7 @@ Context& initializeContextFromGL()
0
};
context = clCreateContext(props, 1, &devices[devUsed], NULL, NULL, &status);
#elif defined(_WIN32)
#elif defined(_WIN32)
cl_context_properties props[] =
{
CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(),
@ -1753,7 +1759,7 @@ Context& initializeContextFromGL()
0
};
context = clCreateContext(props, 1, &devices[devUsed], NULL, NULL, &status);
#elif defined(__linux__)
#elif defined(__linux__)
cl_context_properties props[] =
{
CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
@ -1762,7 +1768,8 @@ Context& initializeContextFromGL()
0
};
context = clCreateContext(props, 1, &devices[devUsed], NULL, NULL, &status);
#endif
#endif
}
if (status != CL_SUCCESS)
CV_Error_(cv::Error::OpenCLInitError, ("OpenCL: Can't create context for OpenGL interop: %d", status));

Loading…
Cancel
Save