MFC堆栈毁坏出错

MFC堆栈损坏出错
void CSectionTestingDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
//*********IplImage-->Mat**************************//
  IplImage *isrc=NULL; //原始图像
  CString strPath;
     if(isrc) cvReleaseImage(&isrc);
  char  szFilter[] = "JPEG Files(*.jpg)|*.jpg|BMP Files (*.bmp)|*.bmp|All Files (*.*)|*.*||";
  CFileDialog dlg( TRUE,"AVI",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter );
   if(dlg.DoModal() == IDOK)

  strPath = dlg.GetPathName(); 
}  
     isrc = cvLoadImage(strPath,1); //显示图片
  IplImage *isrc_gray=cvCreateImage(cvGetSize(isrc),isrc->depth,1);
  Mat src(isrc,0),src_gray(isrc_gray,0);
  cvtColor(src,src_gray,CV_BGR2GRAY);
     DrawPicToHDC(isrc, IDC_STATICSHOWA);
  DrawPicToHDC(isrc_gray, IDC_STATICSHOWB);

//边缘提取算子,sobel算子
     Mat grad_x, grad_y,sobel_image,sobel_image_copy,sobel_image_gray;
     Mat abs_grad_x, abs_grad_y;
  int scale = 1;
     int delta = 0;
     int ddepth = CV_16S;

     /// 求 X方向梯度
     //Scharr( src_gray, grad_x, ddepth, 1, 0, scale, delta, BORDER_DEFAULT );
     Sobel( src_gray, grad_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT );
     convertScaleAbs( grad_x, abs_grad_x );
  
     Sobel( src_gray, grad_y, ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT );
     convertScaleAbs( grad_y, abs_grad_y );
     /// 合并梯度(近似)
  addWeighted( abs_grad_x, 0.5, abs_grad_y, 0.5, 0, sobel_image );
  //IplImage *isobel_image;
  //isobel_image=cvCreateImage(cvSize(sobel_image.cols,sobel_image.rows),CV_16S,3); 

  //find the center of the circle
  CDC* pDC = GetDlgItem(IDC_STATICSHOWC)->GetDC();
     HDC hDC = pDC->GetSafeHdc();
     IplImage isobel_image = sobel_image;
     CvvImage cimg;
   cimg.CopyOf(& isobel_image);
     CRect rect;
     GetDlgItem(IDC_STATICSHOWC)->GetClientRect(&rect);
     cimg.DrawToHDC(hDC, &rect);

     GaussianBlur( sobel_image,sobel_image, Size(9, 9), 2, 2 );
     vector<Vec3f> circles;
     /// Apply the Hough Transform to find the circles
     HoughCircles(sobel_image, circles, CV_HOUGH_GRADIENT, 1, sobel_image.rows/8, 200, 100, 0, 0 );
     /// Draw the circles detected
     for( size_t i = 0; i < circles.size(); i++ )
   {
       Point center(cvRound(circles[0]), cvRound(circles[1]));
       int radius = cvRound(circles[2]);
       //circle center
       circle( sobel_image, center, 3, Scalar(0,255,0), -1, 8, 0 );
       // circle outline
       circle( sobel_image, center, radius, Scalar(0,0,255), 3, 8, 0 );
      }
  CDC* ipDC = GetDlgItem(IDC_STATICSHOWD)->GetDC();
     HDC ihDC = ipDC->GetSafeHdc();
     IplImage iisobel_image = sobel_image;
     CvvImage icimg;
   icimg.CopyOf(& iisobel_image);
     CRect irect;
     GetDlgItem(IDC_STATICSHOWD)->GetClientRect(&irect);
     icimg.DrawToHDC(ihDC, &irect);
}
IDC_STATICSHOWC可以正常显示,画出圆心和半径,IDC_STATICSHOWD不能正常显示,出现下列异常
其原因可能是堆被损坏,这说明 SectionTesting.exe 中或它所加载的任何 DLL 中有 Bug。
原因也可能是用户在 SectionTesting.exe 具有焦点时按下了 F12。
输出窗口可能提供了更多诊断信息。
> SectionTesting.exe!_CrtIsValidHeapPointer(const void * pUserData)  行 2036 C++

调用堆栈结果

------解决方案--------------------
检查一下对应的参数等,是否越界
------解决方案--------------------
边缘搜索的时候如果用的是递归算法,可能会导致堆栈崩溃,增加堆栈大小看看
------解决方案--------------------