ucrtbase.dll: An invalid parameter was passed to a function that considers invalid parameters fatal

Marchius picture Marchius · Oct 16, 2016 · Viewed 14.9k times · Source

I'm currently working on a personal project with OpenCV and I have a few issues during the execution of the program. After implementing an AKAZE + BOW recognizer (which didn't seem to work well enough for my problem) I wanted to try out a SIFT (and eventually SURF) implementation.

For my project I'm following this one found on github and I'm using VS2015 (community) and OpenCV 2.4.13 over Windows 10.

The issue I'm having, as stated in the title, lies with the ucrtbase.dll which gets an invalid parameter during execution (if I read other threads correctly the dll should be an OS library in Windows 10). The problem arises when the for cicle moves onto the second iteration (aka when it's supposed to get the features of another image for the BOW training), this is when the execution stops and the error in the title appears.

I tried various things (eg. using different constructors for the detector/extractor or commenting part of the code) and during the debug session it seems that the error is caused by the detect function but I'm not sure why (also, as stated in the code below, commenting the detect function and those following it fixes the problem).

The drawKeypoints function (used in another test) seems to be drawing the keypoints correctly (which should mean the detect function is working correctly).

Below you can find the snippet that's giving the error:

int main(int argc, char ** argv)
{

    const int nimages = 4;
    const int nclusters = 2;

    const char *datapath = "./database";

    SiftFeatureDetector detector(400);
    SiftDescriptorExtractor extractor;
    Ptr<BOWTrainer> bow_train = makePtr<BOWKMeansTrainer>(nclusters);

    for (int i = 0; i<nimages; i++)
    {

        Mat im, feat;
        std::vector<KeyPoint> kp;

        // read an image from the database
        im = cv::imread(format("%s/%d.png", datapath, i + 1), 1);

        // detect keypoints
        detector.detect(im, kp); // commenting from here avoids the error

        // extract features
        extractor.compute(im, kp, feat);

        // add features for bow training
        bow_train->add(feat);

    }

    /* more stuff here */
}

Tell me if there's anything else you need to know to understand the problem.

Thanks in advance for any help/advice you can give me.

EDIT 1:

I tried removing all for cicles and the program manages to reach the end executing all functions correctly but it's still giving the ucrtbase.dll error when returning from main. Another thing I've noticed during VS debug is that the debugger generates an exception when it has to deallocate memory (using that dll), either during for cicles or at the end of the program.

I guess the debugger here has the solution but I don't really get what's the problem with that dll, any help will be really appreciated if anyone has time to spare.

EDIT 2:

After a few days of testing it seems the error is coming from the deallocation of:

std::vector< cv::KeyPoint >

If KeyPoint vectors are instantiated and only destroyed when the program ends, the computation works just fine and there's the dll error at end (which is annoying but for quick tests I can cope with).

The issue is I'd like to create functions that make use of those vectors without having to pass them as arguments. Since the deallocation seems to be the problem I can't do that without having the program crash after each call to said functions. I have also tried using clear() and swap() on the vector but that didn't work either.

I'll keep trying to figure this out as I keep coding but any help/insight would really be appreciated.

Answer

Mike Pelton picture Mike Pelton · Jun 14, 2017

This issue with crashing on vector deallocation seems to be to do with linking against the wrong version of the OpenCV library. If you're building in Debug you need to be linked against the opencv_world320d.lib (or opencv_world310.lib or the library for whichever version of OpenCV you're using) - the "d" after the version number is significant. For Release configurations use the opencv_worldXXX.lib to link against.

If you're seeing the "invalid parameter was passed to a function that considers..." message this is a symptom of the same issue.