超出范围的 Eigen RowVector 产生 "Run-Time Check Failure #2 - Stack around the variable X was corrupted"

Eigen RowVector out of scope produces "Run-Time Check Failure #2 - Stack around the variable X was corrupted"

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

Run-Time Check Failure #2 - Stack around the variable 'myVariableCopy' was corrupted.

来自以下代码:

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 维向量。