title: ucrtbase.dll: An invalid parameter was passed to a function that considers invalid parameters fatal
body: <p>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.</p>
  
  <p>For my project I'm following this one found on <a href="https://github.com/berak/opencv_smallfry/blob/master/bow/main.cpp" rel="nofollow" title="github">github</a> and I'm using VS2015 (community) and OpenCV 2.4.13 over Windows 10.</p>
  
  <p>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.</p>
  
  <p>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).</p>
  
  <p>The drawKeypoints function (used in another test) seems to be drawing the keypoints correctly (which should mean the detect function is working correctly).</p>
  
  <p>Below you can find the snippet that's giving the error:</p>
  
  <pre><code>int main(int argc, char ** argv)
  {
  
      const int nimages = 4;
      const int nclusters = 2;
  
      const char *datapath = "./database";
  
      SiftFeatureDetector detector(400);
      SiftDescriptorExtractor extractor;
      Ptr&lt;BOWTrainer&gt; bow_train = makePtr&lt;BOWKMeansTrainer&gt;(nclusters);
  
      for (int i = 0; i&lt;nimages; i++)
      {
  
          Mat im, feat;
          std::vector&lt;KeyPoint&gt; 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-&gt;add(feat);
  
      }
  
      /* more stuff here */
  }
  </code></pre>
  
  <p>Tell me if there's anything else you need to know to understand the problem.</p>
  
  <p>Thanks in advance for any help/advice you can give me.</p>
  
  <p>EDIT 1: </p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>EDIT 2:</p>
  
  <p>After a few days of testing it seems the error is coming from the deallocation of:</p>
  
  <blockquote>
    <p>std::vector&lt; cv::KeyPoint > </p>
  </blockquote>
  
  <p>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). </p>
  
  <p>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. </p>
  
  <p>I'll keep trying to figure this out as I keep coding but any help/insight would really be appreciated.</p>