zoukankan      html  css  js  c++  java
  • opencv+vs2015 堆内存析构异常

    最近使用vs2015编译ORB-SLAM2的程序,在debug模式下进行调试运行时碰到了堆内存异常,大致报错内容如下:

    错误:File: minkernelcrtsucrtsrcappcrtheapdebug_heap.cpp 
    Line: 980 
    Expression: __acrt_first_block == header 
    For information on how your program can cause an assertion 
    failure, see the Visual C++ documentation on asserts.

    看了网上大牛们的分析,大致可以归因于链接错误。dll 如果静态链接了运行时库,dll 就会拥有独立于应用程序堆(也称作local heap)的运行时堆实例。此时在 dll 外部就不能访问此 local heap,所以也就有上面所出现的异常。

    检查了一下代码中出错的位置,确实存在这样的情况:

    vector<cv::KeyPoint> vKeysCell;
    FAST(mvImagePyramid[level].rowRange(iniY,maxY).colRange(iniX,maxX), vKeysCell,iniThFAST,
    true);

    其中vKeysCell在调用opencv中的FAST函数时,在其内部被分配了空间,然后在FAST函数外面对vKeysCell进行析构时出现了前面的析构错误。

    简单粗暴的解决办法是在调用FAST函数之前,先分配好内存空间。

    vector<cv::KeyPoint> vKeysCell(10000);

    这样就不会报出上面的错误了。

    除此之外,还可以修改库的链接情况,这种方法比较麻烦,暂时不做考虑。

  • 相关阅读:
    [LintCode] Maximum Subarray Difference
    [HDU 3415] Max Sum of Max-K-sub-sequence
    [LintCode] Count of Smaller Number before itself
    [LeetCode] Invert Binary Tree
    [LintCode] Max Tree
    [LeetCode] Implement Stack using Queues
    [LintCode] Maximum Subarray III
    [LeetCode] Basic Calculator & Basic Calculator II
    [LeetCode] Rectangle Area
    Tensorflow[目录结构]
  • 原文地址:https://www.cnblogs.com/CGwolke/p/7851994.html
Copyright © 2011-2022 走看看