Eigen RowVector超出范围会产生“运行时检查失败#2-变量X周围的堆栈已损坏”

问题描述

我正在使用Eigen库,并得到一个非常奇怪的异常:

运行时检查失败#2-变量'myVariableCopy'周围的堆栈已损坏。

来自以下代码:

void get_new_handle_locations()
{
    int count = 0;
    for (long vi = 0; vi < V.rows(); ++vi)
    {
        if (handle_id[vi] >= 0)
        {
            Eigen::RowVector3f myVariable = V.row(vi).cast<float>();

            if (handle_id[vi] == moving_handle)
            {
                Eigen::RowVector3f myVariableCopy = myVariable;
                myVariable -= handle_centroids.row(moving_handle).cast<float>();
                igl::rotate_by_quat(myVariable.data(),rotation.data(),myVariableCopy.data());
                myVariable = myVariableCopy;
                myVariable += handle_centroids.row(moving_handle).cast<float>();
            }

            handle_vertex_positions.row(count++) = myVariable.cast<double>();
        }
    }
} // This is where the exception is thrown

在循环结束后会引发异常,并且在最后的〜100次迭代中条件没有通过,因此此时变量应确保超出范围

我正在使用VS 2017。

我禁止了此异常,但是我应该担心还是VS错误?

解决方法

损坏的原因是igl::rotate_by_quat调用igl::quat_mult,它期望goalPositionCopy.data()具有4维,但是它被声明为3维向量。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...