From 032b6322fc7c8a2e5b90df0293322cebf61b02e6 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 18 Jun 2015 14:02:01 +0300 Subject: [PATCH] fix MatAllocator creation/destruction issues --- modules/core/src/matrix.cpp | 8 ++++++-- modules/core/src/ocl.cpp | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index b273c8a7d8..5de7e034fd 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -222,10 +222,14 @@ public: } }; +static StdMatAllocator *mat_allocator = NULL; MatAllocator* Mat::getStdAllocator() { - static StdMatAllocator allocator; - return &allocator; + if (mat_allocator == NULL) + { + mat_allocator = new StdMatAllocator(); + } + return mat_allocator; } void swap( Mat& a, Mat& b ) diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index 5d68a36832..4f1231238e 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -5160,10 +5160,15 @@ public: MatAllocator* matStdAllocator; }; +// This line should not force OpenCL runtime initialization! (don't put "new OpenCLAllocator()" here) +static MatAllocator *ocl_allocator = NULL; MatAllocator* getOpenCLAllocator() { - static MatAllocator * allocator = new OpenCLAllocator(); - return allocator; + if (ocl_allocator == NULL) + { + ocl_allocator = new OpenCLAllocator(); + } + return ocl_allocator; } ///////////////////////////////////////////// Utility functions /////////////////////////////////////////////////