I clone openMVG from github, and I build it into static libs. Then I use the openMVG SFM tools for some images, works fine. But when I use openMVG libs in my own project, the program will crash strangely.
For example, I copy exactly openMVG_main_SfMInit_ImageListing.cpp to my own project, and use needed libs to build it, then I run with same input, the program will produce same output but when it exits, there is a double free or corruption error. The error is produced by Intrinsics data.
another example, I copy exactly main_ComputeMatches.cpp to my own project, and use needed libs to build it, then I run with same input, the program will crash in Solver::Solve(x1, x2, models); in robust_estimator_ACRansacKernelAdaptator.hpp 87 line, the crash is because of JacobiSVD in Eigen.
I make sure all all the libs are correct, and inputs are same, codes are same. But during run, the results are different. main_ComputeFeatures.cpp is analogous, which will crash due to vlsift releated code.
I think this problem is caused by memory aligned issues of Eigen or openMVG, but how to fix this, or are there some important issues when building, I have no idea.
I fixed this problem by adding #define EIGEN_MALLOC_ALREADY_ALIGNED 0 in my project. So, this is a problem from Eigen memory aligned issues.
However, when I change the feature matching computation with my own method, the crash reappear again. How to fix?
Then, I found adding #define EIGEN_MALLOC_ALREADY_ALIGNED 32 to my project, it can run successfully. Does someone know the reason?
master
or develop
?develop version is now propagating the compilation preprocessor of each target thanks to cmake.
Does your project that is including OpenMVG is defining special compilation preprocessor?
According Eigen code the value of EIGEN_MALLOC_ALREADY_ALIGNED
should be 0
or 1
https://eigen.tuxfamily.org/dox/Memory_8h_source.html
@pmoulon I was using master, the newest commit. I didn't use special compilation preprocessor, I used gcc 4.9.4 with some params like -pipe -O2 -Wall -W -D_REENTRANT -fPIC, which is default by qmake(I used Qt creator write code).
Can you try to use OpenMVG develop
branch and tell me if it works out of the box (without modification)?
@pmoulon I tried develop branch, and I found it still can not work without the modification
Strange. Can you give more detail about your platform (os, compiler, target x86 x64....)?
Did you set EIGEN_MALLOC_ALREADY_ALIGNED
to valid value?
32
but only 0
or 1
are expected.@pmoulon My OS Ubutun 14.04, compiler is gcc version 7.2.0 (Ubuntu 7.2.0-1ubuntu1~14.04), x86 64bit.
I need to set
DEFINES += EIGEN_MALLOC_ALREADY_ALIGNED=0
DEFINES += EIGEN_MAX_ALIGN_BYTES=32
this 2 macros to make my program work.
Did you try to build a x86 or a 64bit binary?
See here line 703:
https://bitbucket.org/eigen/eigen/src/1f0f8337c029a3a8f2720bfcabbed13579bc9093/Eigen/src/Core/util/Macros.h
So it seems that in one case the AVX instruction are activated (openMVG), but not for your new project.
I think it's because your are defining your new project not by using cmake. Cmake should propagate the compilation flags for the develop
branch.
OK. Thank you for your attention. I have understood this a little.
I mean how did you generated your QT Creator project?
Any information regarding if you are building a x86 or x64 binary would be valuable.
@jby1993 Any feedback?
@pmoulon I'm using .pro to generate my project.
Ok, the best is to use CMake in order to get the compilation flags coming with the target you are using.
I will close the issue, since we found the issue:
I want to ask a crazy question. In Installation instruction 1. $ git clone https://github.com/openMVG/openMVG.git is it for master branch? If right, I want to know how to clone develop branch? Sorry for my question..:P :P
You can change branch once the repository is cloned.
$ git clone https://github.com/openMVG/openMVG.git
$ git checkout develop
$ git submodule init
$ git submodule update
Or do it in one line at cloning time:
$ git clone --recursive https://github.com/openMVG/openMVG.git -b develop
Then you create your build dir, run cmake and the build.
Thank You so much