Very weird MATLAB 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)
-
-
reporter eval() fixes it! But how??
-
reporter - changed status to resolved
fixed using eval(), wondering how we can prevent in future.
-
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 theauto
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 useEigen::Vector3d
or the corresponding real container class instead ofauto
.Cheers
- Log in to comment
Have you tried:
auto sigmas = model->sigmas().head(3).eval();
?