在Windows而不是Linux上堆坏了

时间:2014-04-08 18:15:55

标签: c++ windows visual-studio-2010 opencv heap-corruption

下面是一些简单的OpenCV代码,用于从视频文件创建帧并在帧上运行SURF特征检测器和提取器。当我在Linux和OSX上运行此代码时它运行正常,但是在Windows上我在两个注释行上遇到堆损坏错误。

VideoCapture capture(vidFilename.c_str());
Mat frame;
capture >> frame; 

SurfFeatureDetector *detector = new SurfFeatureDetector(minHessian);
vector<KeyPoint> frameKeypoints;
detector->detect(frame, frameKeypoints);
delete(detector); // Heap Corruption Detected

SurfDescriptorExtractor *extractor = new SurfDescriptorExtractor();
Mat frameDescriptors;
extractor->compute(frame, frameKeypoints, frameDescriptors);
delete(extractor); // Heap Corruption Detected

我不知道代码中可能导致这种情况的原因。我正在使用VS 2010来编译代码,VS中有什么东西会导致这种情况发生吗?

1 个答案:

答案 0 :(得分:1)

如上所述,你没有得到任何与堆损坏相关的异常并不意味着它没有发生。你的代码中会出现问题,而不是VS或编译器。我之前关于类似文章的帖子会很有用在这里。

https://stackoverflow.com/a/22074401/2724703

也许您还应该尝试在Linux上运行一些动态工具(Valgrind)。您很可能会使用Valgrind找到相同的错误。

这些动态工具可以解决这些问题的根本原因。