如何解决vector 析构函数的异常 opencv Assert _CrtIsValidHeapPointer

简介:
+关注继续查看

一气呵成代码,但是,当发生执行_CrtIsValidHeapPointer例外,去搭调了一上午Bug。最终获得


跟踪定位到 _CrtIsValidHeapPointer ,注意到 g 8h"@dbgheap.c 文件里 _CrtIsValidHeapPointer 处凝视:


         /*
         * If this ASSERT fails, a bad pointer has been passed in. It may be
         * totally bogus, or it may have been allocated from another heap.
         * The pointer MUST come from the 'local' heap.
         */


         _ASSERTE(_CrtIsValidHeapPointer(pUserData));


大概是由于 dll 假设静态链接了执行时库,dll 就会拥有独立于应用程序堆(也称作local heap)的执行时堆实例。此时在 dll 外部就不能訪问此 local heap,所以也就有上面所出现的异常啦。MSDN 中也有介绍:


The _CrtIsValidHeapPointer function is used to ensure that a specific memory address is within the local heap. The local heap refers to the heap created and managed by a particular instance of the C run-time library. If a dynamic-link library (DLL) contains a static link to the run-time library, it has its own instance of the run-time heap, and therefore its own heap, independent of the application's local heap. When _DEBUG is not defined, calls to _CrtIsValidHeapPointer are removed during preprocessing.



程序崩溃在当析构一个带有vector成员函数对象的时候,在析构vector时,会出现这个错误,大致原因是由于析构的时候找不到vector分配的空间

一行一行查看代码发现,对象里面的points2, status等vector变量是在calcOpticalFlowPyrLK(img1, img2, points1, points2, status, similarity, window_size, level, term_criteria, lambda, 0); 函数中分配的,即opencv的dll,所以当对象进行析构的时候,由于不能訪问此local heap所以会有异常崩溃。



解决方法:

在调用opencv的函数之前,自己进行空间的分配



另一种可能是由于VS版本号和opencv使用的版本号不一致创建,同hog当检测行人,这似乎是问题

版权声明:本文博客原创文章,博客,未经同意,不得转载。







本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4752294.html,如需转载请自行联系原作者


相关文章
|
1月前
|
安全 程序员 C++
探究C++11智能指针之std::unique_ptr
谈起C++,它被公认为最难学的编程语言之一,不仅语法知识点广泛,细节内容之多,学习难度和学习周期也长,导致好多新入行的开发者对C++“敬而远之”,甚至“从入门到放弃”。自C++11开始,好多C++程序员慢慢的感受到了C++的魅力所在,似乎难度也越来越小。
|
3月前
|
程序员 C语言
assert断言与const修饰指针的妙用(模拟实现strcpy函数)
assert断言与const修饰指针的妙用(模拟实现strcpy函数)
|
4月前
|
C++
|
4月前
|
存储 C++ 容器
|
4月前
|
存储 容器
|
8月前
malloc的使用、用malloc动态分配内存以适应用户的需求的源代码实例
malloc的使用、用malloc动态分配内存以适应用户的需求的源代码实例
|
9月前
解决办法:对‘operator delete(void*)’未定义的引用
解决办法:对‘operator delete(void*)’未定义的引用
95 0
|
11月前
|
IDE Java 编译器
记一次inline使用不当导致编译期Null指针的排查过程
周五的一个下午,我哼着小曲和往常一样合完代码。准备运行试试看,结果build时发现了这样一个异常。
84 0
记一次inline使用不当导致编译期Null指针的排查过程
|
算法 计算机视觉 C++
OpenCV广泛问题,cv::findContours()函数使用时导致的程序崩溃问题的解决方案
OpenCV广泛问题,cv::findContours()函数使用时导致的程序崩溃问题的解决方案
347 0
vector的几种初始化及赋值方式
转自:https://blog.csdn.net/yjunyu/article/details/77728410?locationNum=10&fps=1   vector的几种初始化及赋值方式: (1)不带参数的构...
11305 0
相关产品
机器翻译
推荐文章
更多