dedoardo / polyfit

Perception-aligned clip-art vectorization
MIT License
40 stars 10 forks source link

Eigen assert errors (Clang + Visual Studio 2019) #4

Open ShnitzelKiller opened 4 years ago

ShnitzelKiller commented 4 years ago

For a single simple test example, (data/binary_input/apple-32/input.png), polyfit will sometimes manage to run and produce the desired output, but most of the time it will crash due to an eigen assert in the triangular solver.

Assertion failed: (it && it.index()==i), function run, file .../polyfit/dependencies/eigen/Eigen/src/SparseCore/TriangularSolver.h, line 84.

According to my debug trace, this happens due to CurveSequenceFitter::solve(), called from MultiPolygonTracer::trace(). Is this software not yet stable, or am I doing something wrong (my platform is OS X)?

dedoardo commented 4 years ago

Hi, thank you for trying out the software on OS X and creating the respective pull request for clang :)

The software was developed on Windows using the Visual Studio 2017 compiler and I did not have a chance to test it on other platforms. All the inputs/outputs in the directory run fine under these conditions, but I encounter similar issues with the 2019 compiler, which is probably related to the one you are facing with Clang. I am very sorry about this.

Support for different platform is something worth addressing. To do so the most effective way is probably to (1) set up a unit test, (2) turn on more compiler warnings (3) debug and repeat. Similarly, I am making it more clear in the README that this is an issue.

I am keeping this issue opened as reference (editing the title) and will merge your pull request when I get to do the above, which won't be in the immediate future, but will try to give it a shot in the next weeks.

curves_closed_screen

ShnitzelKiller commented 4 years ago

I did find what I'm pretty sure was a bug (added to my pull request #2 ) relating to bitwise operator precedence. Alas, it still crashes unpredictably. For the two times I have managed to produce output, the results differ:

apple1 apple2

Should results be non-deterministic to this degree?

dedoardo commented 4 years ago

It's not lack of determinism in the algorithm, there is a bug in the code preventing the curve optimization stage to run. I obtain the same result by commenting out multi_polygon.cpp:256 (_solve_curves()). If you look closely, the per-corner primitive classification are the same between the two results, but the curves in the bottom row correspond to the initial guess.

As you pointed out in the first issue, the crashes you were obtaining were exactly in the CurveSequenceFitter::solve(), where the global optimization happens, hence the correlation between the two events.

I presume you managed to obtain the results by running it multiple times on the code compiled on Clang/OS X. As discussed above this is problem needs to be further investigated. I did not test the code on multiple platforms (no doubt I should have done that) and it's unfortunate that it's not showing up in VS2017. I will do my best to investigate it soon, after I've set up a simple test to make sure that outputs remain unchanged between commits.

example

ShnitzelKiller commented 4 years ago

According to my research on the subject, the particular eigen assert error I get can be caused by a non-triangular sparse matrix being passed to the sparse triangular solver.