簡體   English   中英

0xc0000374未進行調試時Cli / Cpp代碼中的堆損壞

[英]0xc0000374 Heap Corruption in Cli/Cpp code when debugging is not attched

我在Cli / cpp項目中遇到堆損壞問題。

僅當未附加調試器或不使用依賴關系遍歷器工具進行性能分析時,情況才出現問題。

在我看來,釋放一些內存時,該應用程序首先在崩潰時崩潰。

如果有人可以看一看,請告訴我我在以下代碼中做的是否真的很糟糕,可能會導致這種情況。

std::string imagePath = msclr::interop::marshal_as< std::string >(Path::Combine(this->context->WorkingDirectory, this->context->Payload->ImagePath));
std::cout << imagePath << std::endl;
cv::Mat image = cv::imread(imagePath);

if (!image.data)
{
    throw gcnew System::Exception("image data is not loaded");
}


std::vector<cv::Point2f> src;
src.push_back(cv::Point2f(0, 0));
src.push_back(cv::Point2f(0, image.rows));
src.push_back(cv::Point2f(image.cols, image.rows));
src.push_back(cv::Point2f(image.cols, 0));

cv::Mat M = cv::getPerspectiveTransform(src, dst);

cv::Mat warp_img((ymax - ymin + 1)*tileSize, (xmax - xmin + 1)*tileSize, CV_8UC3);



std::vector<cv::Point2f> obj_corners(4);
obj_corners[0] = cv::Point(0, 0); obj_corners[1] = cv::Point(image.cols, 0);
obj_corners[2] = cv::Point(image.cols, image.rows); obj_corners[3] = cv::Point(0, image.rows);

std::vector<cv::Point2f> scene_corners(4);

cv::perspectiveTransform(obj_corners, scene_corners, M);

cv::warpPerspective(image, warp_img, M, cv::Size((xmax - xmin + 1)*tileSize, (ymax - ymin + 1)*tileSize));
image.release();


cv::Mat warp_img_fliped;
cv::flip(warp_img, warp_img_fliped, 0);
warp_img.release();

String^ id = Guid::NewGuid().ToString();

std::vector<int> compression_params;
if (this->context->Payload->Extension->Equals(".png")){
    compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
    compression_params.push_back(9);

}
if (this->context->Payload->Extension->Equals(".jpg")){
    compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
    compression_params.push_back(this->context->Payload->Quality);

}

for (int r = 0, rr = (ymax - ymin + 1)*tileSize, ty_idx = ymax; r < rr; r += tileSize, ty_idx--){
    for (int c = 0, cc = (xmax - xmin + 1)*tileSize, tx_idx = xmin; c < cc; c += tileSize, tx_idx++)
    {
        std::cout << ty_idx << " " << tx_idx << std::endl;

        cv::Mat tile = warp_img_fliped(cv::Rect(c, r, tileSize, tileSize)); 

        String^ Path = Path::Combine(this->context->WorkingDirectory, id,String::Format("{0}\\{1}\\{2}\\{3}", zoom,tx_idx,ty_idx, this->context->Payload->Extension));
        Directory::CreateDirectory(Path::GetDirectoryName(Path));               
        std::string path = msclr::interop::marshal_as< std::string >(Path);
        cv::imwrite(path, tile, compression_params);
    }
}
warp_img_fliped.release();

因此,錯誤甚至發生在我上面發布的代碼之前。

通過一次一行返回,我能夠找到導致堆損壞的原因。

double pxpy[2] = { (double)xmin * tileSize, (double)ymin * tileSize };  
pixelsToMeters(pxpy, zoom, initialResolution, mxmy);

上面的作品和下面的是導致錯誤

pixelsToMeters(new double[] { (double)xmin * tileSize, (double)ymin * tileSize }, zoom, initialResolution, mxmy);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM