Very weird MATLAB issue

Issue #451 resolved
Frank Dellaert created an issue

This is in code not yet checked in anywhere, but the line below - where model is a 6-dimensional SharedDiagonal instance - makes sigmas(0) point to un-initialized memory but only when this code is called from within MATLAB. I don't even begin to understand how that is possible. This could point to some underlying issue that could be a reason for some other unexplained MATLAB crashes.

auto sigmas = model->sigmas().head(3);

This fixes it (but sigmas is now a 6D vector):

const auto& sigmas = model->sigmas();

Comments (4)

  1. José Luis Blanco-Claraco

    Good! :-)

    auto with Eigen is a bit tricky... head(), tail(), block(), "*", etc. all do NOT return matrices, but lazy-evaluation expression proxy classes. For some reason, in this case the proxy object in your first expression might be dangling if the original object is modified, realloc'd, destroyed, etc. since the auto variable is defined, until it is actually accessed. I'm just guessing since I don't see the context, but that's probably what happened...

    The solution in general is either use eval() after Eigen expressions, if using auto, or just use Eigen::Vector3d or the corresponding real container class instead of auto.

    Cheers

  2. Log in to comment