alecjacobson / gptoolbox

Matlab toolbox for Geometry Processing.
MIT License
629 stars 169 forks source link

Unexpected Standard exception What() is:vector when calling mex principal_curvature #139

Open paul0noah opened 2 years ago

paul0noah commented 2 years ago

Hi, I want to use the mex files (especially principal_curvatures) in Matlab on my M1 Pro Macbook Pro. I am running Matlab 2019b. I installed and build using the following steps:

I have the following simple tetrahedron as a shape

V = [0.1 0 0;
0 1 0;
0.9 0 0;
0.5 0.5 0.5];
F = [1 2 3;
1 4 2;
1 3 4;
3 2 4];

When calling principal curvatures as follows: [PD1,PD2,PV1,PV2] = principal_curvature(V, F-1); Matlab returns:

Unexpected Standard exception from MEX file.
What() is:vector
..

Is there a fix for this?

alecjacobson commented 2 years ago

First, you should just call:

[PD1,PD2,PV1,PV2] = principal_curvature(V, F);

However, this will still crash on your example. I think this is an edge case of principal_curvature and maybe in turn igl::principal_curvature which works by fitting a small neighborhood of vertices. I'm guessing that having only 4 vertices total is making it confused. @sgsellan do you know?

paul0noah commented 2 years ago

Hi @alecjacobson , thanks for the fast reply! I tested it with a larger shape and works indeed :)

I also did some digging: Error occurs in these lines (std::vector is accessed out of range)

This is caused since

curvDir[i]

is never initialized due to some if (vv.size() < 6) in these lines.