void CDlgConfig::CalcMap(void) { m_pXofs = new int[m_dst->width]; m_pYofs = new int[m_dst->height]; double ifx = 1./inv_scale_x, ify = 1./inv_scale_y; int x ,y; // dst中位置对应src中的位置 for( x = 0; x < m_dst->width; x++ ) { int sx = saturate_cast<int>(x*ifx); m_pXofs[x] = std::min(sx, m_src->width-1); } for( y = 0; y < m_dst->height; y++ ) { int sy = saturate_cast<int>(y*ify); m_pXofs[y] = std::min(sy, m_src->height-1); } // src 中的位置,对应dst的位置 // saturate_cast<int> std::min(x*inv_scale_x,m_dst->widht-1) }
原因:
m_pXofs[y] = std::min(sy, m_src->height-1);
错误。y大于了 new int[] 分配的值。从而破坏了堆
从目前的代码看,应该就是以下问题了 从你的方法void Read1(int * data, long n);分析讨论 由于这个方法的第一个参数是data并非为const,也就是执行完这个函数后,main中data与Read1中的地址相同,到此时还未问题 由于没有给出Read2、Read3、Read5,无法判断,LZ可以自己看看这些函数 因为main中int * data=new int[n];即只分配了n个int大小的内存 如果在Read2、Read3、Read5执行后,数组变大了,就会出现这种问题