2023年6月24日发(作者:)
如何解决vector析构函数的异常opencvAssert_CrtIsValidHeapP。。。⼀⽓呵成代码,但是,当发⽣执⾏_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. Thelocal heap refers to the heap created and managed by a particular instance of the C run-time library. If a dynamic-linklibrary (DLL) contains a static link to the run-time library, it has its own instance of the run-time heap, and therefore its ownheap, independent of the application's local heap. When _DEBUG is not defined, calls to _CrtIsValidHeapPointer areremoved 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当检测⾏⼈,这似乎是问题版权声明:本⽂博客原创⽂章,博客,未经同意,不得转载。
发布者:admin,转转请注明出处:http://www.yc00.com/news/1687607223a24181.html
评论列表(0条)