title: OpenCV _CRT_DEBUGGER_HOOK error. C++
body: <p>I have a strange issue with my OpenCV application.
  I've written a function which task is to compute position of the biggest red object on camera screen. Everything works fine, but if i put something bigger in front of the camera, something that takes 40% of screen area, the app crashes with  _CRT_DEBUGGER_HOOK error according to VS2015.
  I'am using opencv x64 libraries, and x64 built boost asio libraries for transffering data between applications.</p>
  
  <p>Here is code of problematic function:</p>
  
  <pre><code>Result * ImageProcessor::processImage(Mat &amp;mat) {
  
      Scalar min(config.FROM_VALUE_RANGE, config.FROM_SATURATION_RANGE, config.FROM_HUE_RANGE);
      Scalar max(config.TO_VALUE_RANGE, config.TO_SATURATION_RANGE, config.TO_HUE_RANGE);
  
      Mat treshHold(config.RESOLUTION_HEIGHT, config.RESOLUTION_WIDTH, CV_8UC3);
      Mat erodeKernel = getStructuringElement(MORPH_ELLIPSE, Size(config.ERODE_KERNEL_CIRCLE_SIZE, config.ERODE_KERNEL_CIRCLE_SIZE));
      Mat dilateKernel = getStructuringElement(MORPH_ELLIPSE, Size(config.DILATE_KERNEL_CIRCLE_SIZE, config.DILATE_KERNEL_CIRCLE_SIZE));
  
      cvtColor(mat, treshHold, COLOR_RGB2HSV);
      inRange(treshHold, min, max, treshHold);
      erode(treshHold, treshHold, erodeKernel);
      dilate(treshHold, treshHold, dilateKernel);
      medianBlur(treshHold, treshHold, config.MEDIAN_BLUR);
  
      if (countNonZero(treshHold) &lt; config.MIN_ON_PIXELS) {
          return nullptr;
      }
  
      vector&lt;vector&lt;Point&gt; &gt; contours;
      vector&lt;Vec4i&gt; hierarchy;
  
      Canny(treshHold, treshHold, 0, 1);
      findContours(treshHold, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
  
      vector&lt;Point&gt; biggestVec = vector&lt;Point&gt;();
      for (vector&lt;Point&gt; vec : contours) {
          if (vec.size() &gt; biggestVec.size()) {
              biggestVec = vec;
          }
      }
  
      if (config.SHOW) {
          drawContours(treshHold, contours, 0, config.WHITE_SCALAR, 2);
      }
  
      if (biggestVec.size() == 0) {
          return nullptr;
      }
  
      Rect rect = boundingRect(biggestVec);
      Point center = Point(rect.x + rect.height / 2, rect.y + rect.height / 2);
  
      addPointToList(center);
  
      if (config.SHOW) {
          int size = pointList.size();
          if (size &gt;= 2) {
  
              std::list&lt;Point&gt;::iterator firstIter = pointList.begin();
              std::list&lt;Point&gt;::iterator secondIter = pointList.begin();
  
              std::advance(firstIter, size - 2);
              std::advance(secondIter, size - 1);
              drawVector(treshHold, *firstIter, *secondIter);
          }
          circle(treshHold, center, 0, config.WHITE_SCALAR);
          circle(treshHold, center, rect.height / 2, config.WHITE_SCALAR);
  
          String img_pos = "IMG_POS : " + to_string(center.x) + ", " + to_string(center.y);
          String real_pos = "REAL_POS : " + to_string((center.x * (config.RATIO))) + ", " + to_string((center.y * (config.RATIO)));
  
          putText(treshHold, img_pos, Point(0, 40), FONT_HERSHEY_COMPLEX, 0.3, config.WHITE_SCALAR);
          putText(treshHold, real_pos, Point(0, 20), FONT_HERSHEY_COMPLEX, 0.3, config.WHITE_SCALAR);
      }
  
      if (config.SHOW) {
          imshow("Before", mat);
          imshow("After", treshHold);
      }
  
      if (pointList.size() &lt; 2) {
          return nullptr;
      }
  
      return new Result(pointList, config);
  }
  </code></pre>
  
  <p>Thanks in advance!</p>
  
  <p><strong>EDIT:</strong>
  After disabling VS2015 optimization, program exits with code -1073740777.
  While debugging (optimization on and off) i noticed that program crashes while returning from given function.</p>