ocl: cleanup workarounds
authorAlexander Alekhin <alexander.alekhin@itseez.com>
Thu, 13 Mar 2014 11:45:23 +0000 (15:45 +0400)
committerAlexander Alekhin <alexander.alekhin@itseez.com>
Thu, 13 Mar 2014 11:46:38 +0000 (15:46 +0400)
modules/core/src/ocl.cpp

index c05df1e..51f34e0 100644 (file)
@@ -2476,23 +2476,23 @@ const Device& Context::device(size_t idx) const
 
 Context& Context::getDefault(bool initialize)
 {
-    static Context ctx;
-    if(!ctx.p && haveOpenCL())
+    static Context* ctx = new Context();
+    if(!ctx->p && haveOpenCL())
     {
-        if (!ctx.p)
-            ctx.p = new Impl();
+        if (!ctx->p)
+            ctx->p = new Impl();
         if (initialize)
         {
             // do not create new Context right away.
             // First, try to retrieve existing context of the same type.
             // In its turn, Platform::getContext() may call Context::create()
             // if there is no such context.
-            if (ctx.p->handle == NULL)
-                ctx.p->setDefault();
+            if (ctx->p->handle == NULL)
+                ctx->p->setDefault();
         }
     }
 
-    return ctx;
+    return *ctx;
 }
 
 Program Context::getProg(const ProgramSource& prog,
@@ -3122,7 +3122,12 @@ struct Program::Impl
     {
         if( handle )
         {
-            clReleaseProgram(handle);
+#ifdef _WIN32
+            if (!cv::__termination)
+#endif
+            {
+                clReleaseProgram(handle);
+            }
             handle = NULL;
         }
     }