Merge pull request #847 from stweil/crash

opencl: Fix crash on hosts with no OpenCL platform
This commit is contained in:
zdenop 2017-04-27 09:01:11 +02:00 committed by GitHub
commit 72b86e098f

View File

@ -170,15 +170,15 @@ static ds_status initDSProfile(ds_profile** p, const char* version) {
memset(profile, 0, sizeof(ds_profile));
clGetPlatformIDs(0, nullptr, &numPlatforms);
if (numPlatforms == 0)
goto cleanup;
platforms = (cl_platform_id*)malloc(numPlatforms*sizeof(cl_platform_id));
if (platforms == nullptr) {
status = DS_MEMORY_ERROR;
goto cleanup;
if (numPlatforms > 0) {
platforms = (cl_platform_id*)malloc(numPlatforms*sizeof(cl_platform_id));
if (platforms == nullptr) {
status = DS_MEMORY_ERROR;
goto cleanup;
}
clGetPlatformIDs(numPlatforms, platforms, nullptr);
}
clGetPlatformIDs(numPlatforms, platforms, nullptr);
numDevices = 0;
for (i = 0; i < (unsigned int)numPlatforms; i++) {