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

Viewed 93

I'm using Eigen library and get this very strange exception:

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

It's from the following code:

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

The exception is raised after the loop ends, and the condition doesn't pass for the last ~100 iterations so the variable should be out of scope for sure at this point

I'm using VS 2017.

I suppressed this exception but is there something I should worry about or is it a VS bug?

1 Answers

The cause of the corruption is that igl::rotate_by_quat calls igl::quat_mult which expects goalPositionCopy.data() to have 4 dimensions, but it's declared as a 3-dimenional vector.

Related