From 89528d7c3a9f2b5ea365f2ae4988390ab2ca71ab Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sat, 28 Jul 2018 10:29:26 +0000 Subject: [PATCH] core(ocl): don't expose exceptions from OpenCL callback to avoid silent crashes of OpenCL worker threads. --- modules/core/src/ocl.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index cc6feacbbb..05f128baa7 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -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"); + } } }