双空闲或内存分配错误
Double free or memory allocation error
我是C++编程新手,我在代码的一部分中遇到了这个问题,其中错误有时是内存分配类型错误,有时是双重释放错误。
错误代码如下。
cv::Mat obstacles = cv::Mat::ones(output.size(), CV_8UC1);
for (int r=0; r<obstacles.rows; ++r) {
int x_cord = cvRound((r - intercet)/slope);
if (x_cord >= 0 && x_cord <= disp_size){
for (int c=0; c<obstacles.cols; ++c) {
int d = output.at<int>(r,c);
if ((d/(256/disp_size)) <= x_cord+5){//<= x_cord+5 && d>= x_cord-5){
obstacles.at<int>(r,c) = 0; //error is in this line
}
}
}
}
如果我删除obstacles.at<int>(r,c) = 0;
行,就不会有任何错误。
我不明白这一点,因为r
和c
分别只是矩阵行号和列号的obstacles
。
任何帮助。
您的垫子的类型CV_8UC1
是8位= 1字节数据类型。
您尝试以.at<int>
身份访问,但 int 是 32 位数据类型。
请尝试使用无符号字符或其他 8 位类型,如下所示:
cv::Mat obstacles = cv::Mat::ones(output.size(), CV_8UC1);
for (int r=0; r<obstacles.rows; ++r) {
int x_cord = cvRound((r - intercet)/slope);
if (x_cord >= 0 && x_cord <= disp_size){
for (int c=0; c<obstacles.cols; ++c) {
int d = output.at<uchar>(r,c);
if ((d/(256/disp_size)) <= x_cord+5){//<= x_cord+5 && d>= x_cord-5){
obstacles.at<uchar>(r,c) = 0; //error is in this line
}
}
}
}
相关文章:
- vector.resize()中的分配错误
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 0xC0000005:访问冲突写入位置0xCDCDCDCD动态分配错误
- 如何处理以下代码中的内存分配错误
- 动态内存分配错误
- C++向量上的分配错误
- libtorrent file_storage无效:分配错误
- 数组大小分配错误
- 只读位置'__result.std::_Rb_tree_const_iterator<_Tp>::operator*<long long int>()'分配错误
- C++ 内存分配错误?
- 具有特征成员变量分类和分配错误的C 类
- 为什么这种递归子集和算法会导致指针分配错误
- CSTRING分配错误
- 运行时间内存分配错误
- 以下C++代码给出了一些内存分配错误
- 尝试在c++中创建USRP对象时分配错误
- 多阵列动态内存分配错误
- C++:矢量分配错误
- 通过结构指针访问结构变量分配错误数据
- 声明向量时出现神秘的 malloc 内存分配错误