fix MatAllocator creation/destruction issues
authorAlexander Alekhin <alexander.alekhin@itseez.com>
Thu, 18 Jun 2015 11:02:01 +0000 (14:02 +0300)
committerAlexander Alekhin <alexander.alekhin@itseez.com>
Thu, 18 Jun 2015 11:02:01 +0000 (14:02 +0300)
modules/core/src/matrix.cpp
modules/core/src/ocl.cpp

index b273c8a..5de7e03 100644 (file)
@@ -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 )
index 5d68a36..4f12312 100644 (file)
@@ -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 /////////////////////////////////////////////////