diff --git a/modules/core/src/matrix_wrap.cpp b/modules/core/src/matrix_wrap.cpp index d410ab7719..8d9e984bc8 100644 --- a/modules/core/src/matrix_wrap.cpp +++ b/modules/core/src/matrix_wrap.cpp @@ -1247,6 +1247,7 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i, { CV_Assert( i < 0 ); Mat& m = *(Mat*)obj; + CV_Assert(!(m.empty() && fixedType() && fixedSize()) && "Can't reallocate empty Mat with locked layout (probably due to misused 'const' modifier)"); if (allowTransposed && !m.empty() && d == 2 && m.dims == 2 && m.type() == mtype && m.rows == sizes[1] && m.cols == sizes[0] && @@ -1260,13 +1261,13 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i, if(CV_MAT_CN(mtype) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0 ) mtype = m.type(); else - CV_CheckTypeEQ(m.type(), CV_MAT_TYPE(mtype), ""); + CV_CheckTypeEQ(m.type(), CV_MAT_TYPE(mtype), "Can't reallocate Mat with locked type (probably due to misused 'const' modifier)"); } if(fixedSize()) { - CV_CheckEQ(m.dims, d, ""); + CV_CheckEQ(m.dims, d, "Can't reallocate Mat with locked size (probably due to misused 'const' modifier)"); for(int j = 0; j < d; ++j) - CV_CheckEQ(m.size[j], sizes[j], ""); + CV_CheckEQ(m.size[j], sizes[j], "Can't reallocate Mat with locked size (probably due to misused 'const' modifier)"); } m.create(d, sizes, mtype); return; @@ -1276,6 +1277,7 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i, { CV_Assert( i < 0 ); UMat& m = *(UMat*)obj; + CV_Assert(!(m.empty() && fixedType() && fixedSize()) && "Can't reallocate empty UMat with locked layout (probably due to misused 'const' modifier)"); if (allowTransposed && !m.empty() && d == 2 && m.dims == 2 && m.type() == mtype && m.rows == sizes[1] && m.cols == sizes[0] && @@ -1289,13 +1291,13 @@ void _OutputArray::create(int d, const int* sizes, int mtype, int i, if(CV_MAT_CN(mtype) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0 ) mtype = m.type(); else - CV_CheckTypeEQ(m.type(), CV_MAT_TYPE(mtype), ""); + CV_CheckTypeEQ(m.type(), CV_MAT_TYPE(mtype), "Can't reallocate UMat with locked type (probably due to misused 'const' modifier)"); } if(fixedSize()) { - CV_CheckEQ(m.dims, d, ""); + CV_CheckEQ(m.dims, d, "Can't reallocate UMat with locked size (probably due to misused 'const' modifier)"); for(int j = 0; j < d; ++j) - CV_CheckEQ(m.size[j], sizes[j], ""); + CV_CheckEQ(m.size[j], sizes[j], "Can't reallocate UMat with locked size (probably due to misused 'const' modifier)"); } m.create(d, sizes, mtype); return;