more guarding

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

@ -1641,11 +1641,11 @@ Context& initializeContextFromGL()
#elif !defined(HAVE_OPENCL_OPENGL_SHARING) #elif !defined(HAVE_OPENCL_OPENGL_SHARING)
NO_OPENCL_SHARING_ERROR; NO_OPENCL_SHARING_ERROR;
#else #else
cl_uint platformsCnt; cl_uint platformsCnt = 0;
cl_uint devCnt; cl_uint devCnt = 0;
cl_device_id* devices; cl_device_id* devices = nullptr;
cl_uint devUsed; cl_uint devUsed = 0;
cl_context context; cl_context context = nullptr;
cl_int status = clGetPlatformIDs(0, NULL, &platformsCnt); cl_int status = clGetPlatformIDs(0, NULL, &platformsCnt);
if (status != CL_SUCCESS) if (status != CL_SUCCESS)
@ -1667,6 +1667,7 @@ Context& initializeContextFromGL()
if (status != CL_SUCCESS) if (status != CL_SUCCESS)
CV_Error_(cv::Error::OpenCLInitError, ("OpenCL: No devices available: %d", status)); CV_Error_(cv::Error::OpenCLInitError, ("OpenCL: No devices available: %d", status));
try {
devices = new cl_device_id[devCnt]; devices = new cl_device_id[devCnt];
status = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_GPU, devCnt, devices, NULL); 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); status = clGetDeviceInfo(devices[j], CL_DEVICE_EXTENSIONS, extensionSize, extensions, &extensionSize);
if (status != CL_SUCCESS) if (status != CL_SUCCESS)
continue; continue;
} catch(std::exception& ex) { } catch(...) {
CV_Error(cv::Error::OpenCLInitError, "OpenCL: Exception thrown during device extensions gathering"); CV_Error(cv::Error::OpenCLInitError, "OpenCL: Exception thrown during device extensions gathering");
} }
@ -1721,10 +1722,15 @@ Context& initializeContextFromGL()
} }
} }
} }
} catch(...) {
if (!sharingSupported) CV_Error(cv::Error::OpenCLInitError, "OpenCL: Exception thrown during device information gathering");
if(devices != nullptr) {
delete[] devices;
}
continue; continue;
}
if (sharingSupported) {
// Define OS-specific context properties and create the OpenCL context // Define OS-specific context properties and create the OpenCL context
#if defined (__APPLE__) #if defined (__APPLE__)
CGLContextObj cglContext = CGLGetCurrentContext(); CGLContextObj cglContext = CGLGetCurrentContext();
@ -1763,6 +1769,7 @@ Context& initializeContextFromGL()
}; };
context = clCreateContext(props, 1, &devices[devUsed], NULL, NULL, &status); context = clCreateContext(props, 1, &devices[devUsed], NULL, NULL, &status);
#endif #endif
}
if (status != CL_SUCCESS) if (status != CL_SUCCESS)
CV_Error_(cv::Error::OpenCLInitError, ("OpenCL: Can't create context for OpenGL interop: %d", status)); CV_Error_(cv::Error::OpenCLInitError, ("OpenCL: Can't create context for OpenGL interop: %d", status));

Loading…
Cancel
Save