vendredi 8 mai 2015

OpenCV heap corruption on Release mode

I have a simple code written in Visual Studio 2010 with openCV 2.4.10 which extracts some features from some input file.

Mat extractSIFT(Mat img)
{
    cv::Ptr<cv::FeatureDetector> detector;
    cv::Ptr<cv::Feature2D> descriptorExtractor;

    detector = cv::FeatureDetector::create("Dense");
    descriptorExtractor = cv::DescriptorExtractor::create("SIFT");

    detector->set("initXyStep",GRID_SPACING);

    vector<cv::KeyPoint> keypoints;
    detector->detect(img,keypoints);

    Mat o;
    //Mat o(keypoints.size(),128,CV_8U);
    descriptorExtractor->compute(img,keypoints,o);

    return o;
}

Although this code works fine in debug mode(albeit slow), it gives this error:

Windows has triggered a breakpoint in Prototype.exe.

This may be due to a corruption of the heap, which indicates a bug in Prototype.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while Prototype.exe has focus.

The output window may have more diagnostic information.

Upon further investigation, I found that the output variable o cannot be seen in release mode(hover over), but can print values on simple console dump.

In disassembler:

   848:     //Mat o(keypoints.size(),128,CV_8U);
   849:     descriptorExtractor->compute(img,keypoints,o);
   850: 
   851:     return o;
013F6FCF 56                   push        esi  
013F6FD0 8D 55 C0             lea         edx,[keypoints]  
013F6FD3 52                   push        edx  
013F6FD4 8D 45 0C             lea         eax,[img]  
013F6FD7 50                   push        eax  
013F6FD8 8B CF                mov         ecx,edi  
013F6FDA C7 45 F0 01 00 00 00 mov         dword ptr [ebp-10h],1  
013F6FE1 E8 42 35 02 00       call        cv::Feature2D::compute (141A528h)  
013F6FE6 8B 45 C0             mov         eax,dword ptr [keypoints]  
013F6FE9 3B C3                cmp         eax,ebx  
013F6FEB 74 09                je          extractSIFT4+306h (13F6FF6h)  
013F6FED 50                   push        eax  
**013F6FEE E8 EC 5C 02 00       call        operator delete (141CCDFh)**  
013F6FF3 83 C4 04             add         esp,4  

The error occurs in line with asterisks. I tried several project properties (/Md, MT, incremental build,...) recompiled openCV, checked platform version(v100) but no avail.

Aucun commentaire:

Enregistrer un commentaire