Skip to content

Commit 1e11b16

Browse files
committed
opencl: Fix crash on hosts with no OpenCL platform
A Tesseract binary with OpenCL support can also run on a host without any OpenCL platform, as it simply uses the normal CPU based code. Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 50f92c8 commit 1e11b16

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

opencl/openclwrapper.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ static ds_status initDSProfile(ds_profile** p, const char* version) {
170170
memset(profile, 0, sizeof(ds_profile));
171171

172172
clGetPlatformIDs(0, nullptr, &numPlatforms);
173-
if (numPlatforms == 0)
174-
goto cleanup;
175173

176-
platforms = (cl_platform_id*)malloc(numPlatforms*sizeof(cl_platform_id));
177-
if (platforms == nullptr) {
178-
status = DS_MEMORY_ERROR;
179-
goto cleanup;
174+
if (numPlatforms > 0) {
175+
platforms = (cl_platform_id*)malloc(numPlatforms*sizeof(cl_platform_id));
176+
if (platforms == nullptr) {
177+
status = DS_MEMORY_ERROR;
178+
goto cleanup;
179+
}
180+
clGetPlatformIDs(numPlatforms, platforms, nullptr);
180181
}
181-
clGetPlatformIDs(numPlatforms, platforms, nullptr);
182182

183183
numDevices = 0;
184184
for (i = 0; i < (unsigned int)numPlatforms; i++) {

0 commit comments

Comments
 (0)