Skip to content

Commit edcd2c0

Browse files
committed
Merge pull request opencv#4176 from alalek:issue_4461
2 parents e2b677d + 88e6669 commit edcd2c0

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

modules/core/src/umatrix.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,20 @@ UMat Mat::getUMat(int accessFlags, UMatUsageFlags usageFlags) const
230230
a = a0;
231231
temp_u = a->allocate(dims, size.p, type(), data, step.p, accessFlags, usageFlags);
232232
}
233-
UMat::getStdAllocator()->allocate(temp_u, accessFlags, usageFlags); // TODO result is not checked
233+
bool allocated = false;
234+
try
235+
{
236+
allocated = UMat::getStdAllocator()->allocate(temp_u, accessFlags, usageFlags);
237+
}
238+
catch (const cv::Exception& e)
239+
{
240+
fprintf(stderr, "Exception: %s\n", e.what());
241+
}
242+
if (!allocated)
243+
{
244+
allocated = getStdAllocator()->allocate(temp_u, accessFlags, usageFlags);
245+
CV_Assert(allocated);
246+
}
234247
hdr.flags = flags;
235248
setSize(hdr, dims, size.p, step.p);
236249
finalizeHdr(hdr);
@@ -269,8 +282,11 @@ void UMat::create(int d, const int* _sizes, int _type, UMatUsageFlags _usageFlag
269282
if( total() > 0 )
270283
{
271284
MatAllocator *a = allocator, *a0 = getStdAllocator();
272-
if(!a)
285+
if (!a)
286+
{
273287
a = a0;
288+
a0 = Mat::getStdAllocator();
289+
}
274290
try
275291
{
276292
u = a->allocate(dims, size, _type, 0, step.p, 0, usageFlags);

0 commit comments

Comments
 (0)