core(ocl): don't expose exceptions from OpenCL callback
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Sat, 28 Jul 2018 10:29:26 +0000 (10:29 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Sat, 28 Jul 2018 10:29:26 +0000 (10:29 +0000)
to avoid silent crashes of OpenCL worker threads.

modules/core/src/ocl.cpp

index cc6feac..05f128b 100644 (file)
@@ -2834,7 +2834,22 @@ extern "C" {
 
 static void CL_CALLBACK oclCleanupCallback(cl_event e, cl_int, void *p)
 {
-    ((cv::ocl::Kernel::Impl*)p)->finit(e);
+    try
+    {
+        ((cv::ocl::Kernel::Impl*)p)->finit(e);
+    }
+    catch (const cv::Exception& exc)
+    {
+        CV_LOG_ERROR(NULL, "OCL: Unexpected OpenCV exception in OpenCL callback: " << exc.what());
+    }
+    catch (const std::exception& exc)
+    {
+        CV_LOG_ERROR(NULL, "OCL: Unexpected C++ exception in OpenCL callback: " << exc.what());
+    }
+    catch (...)
+    {
+        CV_LOG_ERROR(NULL, "OCL: Unexpected unknown C++ exception in OpenCL callback");
+    }
 }
 
 }