How to solve the vector destructor exception OpenCV Assert _CrtIsValidHeapPointer

Source: Internet
Author: User
Tags assert

Code coherent, but the runtime will appear _CrtIsValidHeapPointer exception, followed in the morning to adjust the bug, and finally fix


Trace to _CrtIsValidHeapPointer, noting _CrtIsValidHeapPointer notes in the G 8h "@dbgheap. C File:


/*
* If This asserts fails, a bad pointer has been passed in. It May is
* Totally bogus, or it may have been allocated from another heap.
* The pointer must come from the ' local ' heap.
*/


_asserte (_CrtIsValidHeapPointer (puserdata));


Probably because DLLs if the Run-time library is statically linked, the DLL has a run-time heap instance that is independent of the application heap (also known as local heap). This local heap is not accessible outside of the DLL, so there is an exception that appears above. Also described in MSDN:


The _CrtIsValidHeapPointer function is used to ensure this 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 the 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 he AP, and therefore its own heap, independent to the application ' s local heap. When _DEBUG isn't defined, calls to _CrtIsValidHeapPointer are removed.



program crashes when a vector member function object is destructor, this error occurs when the vector is being refactored, largely because the vector allocated space is not found at the time of the destructor

Line by line View Code discovery, objects inside the points2, status and other vector variables are in calcopticalflowpyrlk (IMG1, Img2, Points1, points2, status, similarity, Window_size, level, Term_criteria, lambda, 0); The OpenCV DLL that is allocated in the function, so there will be an abnormal crash when the object is destructor because it cannot access this local heap.



Workaround:

Allocate the space yourself before calling the OpenCV function



Another possibility is that the version of VS and OpenCV are inconsistent, which is what happens when you use hog for pedestrian testing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.