allocate CPU memory if Tegra GPU allocator failed.
authorMarina Kolpakova <no@email>
Fri, 16 Mar 2012 14:11:39 +0000 (14:11 +0000)
committerMarina Kolpakova <no@email>
Fri, 16 Mar 2012 14:11:39 +0000 (14:11 +0000)
modules/core/src/matrix.cpp

index cf1bbfe..1c93f9e 100644 (file)
@@ -217,8 +217,23 @@ void Mat::create(int d, const int* _sizes, int _type)
         }
         else
         {
+#ifdef HAVE_TGPU
+           try 
+            {
+                allocator->allocate(dims, size, _type, refcount, datastart, data, step.p);
+                CV_Assert( step[dims-1] == (size_t)CV_ELEM_SIZE(flags) );
+            }catch(...)
+            {
+                allocator = 0;
+                size_t total = alignSize(step.p[0]*size.p[0], (int)sizeof(*refcount));
+                data = datastart = (uchar*)fastMalloc(total + (int)sizeof(*refcount));
+                refcount = (int*)(data + total);
+                *refcount = 1;
+            }
+#else
             allocator->allocate(dims, size, _type, refcount, datastart, data, step.p);
             CV_Assert( step[dims-1] == (size_t)CV_ELEM_SIZE(flags) );
+#endif
         }
     }