laurentkneip / opengv

OpenGV is a collection of computer vision methods for solving geometric vision problems. It is hosted and maintained by the Mobile Perception Lab of ShanghaiTech.
Other
1.02k stars 353 forks source link

Segmentation fault during Central Relative Pose model computation in Linux #47

Closed gregyharra closed 7 years ago

gregyharra commented 7 years ago

I am currently using OpenGV in order to find the central relative pose between two stereos.

I have tested the code under OSX and it works but for some reasons the model computation provided by OpenGV throws a segmentation fault when running the code under Linux Ubuntu.

I ran the program with GDB to get an idea of the issue and this is the backtrace that I get

screen shot 2017-06-12 at 10 17 01 am

I am also running Eigen 3.3.3. Could you help me figure out a way to fix this issue?

Cheers

pmoulon commented 7 years ago

Could be a alignment issue on Matrix of size (3,4)?

gregyharra commented 7 years ago

I thank you for the answer but I have found the solution to this issue.

The solution that I found was that I had to add flag the “-std=c++11” when I compiled the code as OpenGV but it was not enough. I am also using another library to compute the bearing vectors, that are then inputed to the central posed adapter. This is were the error was. This library also uses Eigen but has the flag “-march=native” used during installation. For some reason that I am unable to tell you, and to be honest I haven’t look into it, OS X is not affected by the fact that the last flag is not set while Linux Ubuntu does.

pmoulon commented 7 years ago

What was your final solution?

gregyharra commented 7 years ago

No, I use -march=native to compile my own code.

If you want to verify this, run their demo code:

$ cd <opengv_build_dir> $ cmake ..; make -j8 then $ cd bin $ ./test_relative_pos_sac or ./bin/test_relative_pose_sac

this should compile and run normally without any segmentation faults.

Once again I have not looked into it but my guess is that, because my code was not compile with the -march=native. But my guess is that if you look at the OpenGV CMakeLists.txt, it states:

IF(MSVC): 
  add_compile_option(...) 
else():
  add_definitions(-Wall -march=native -03)
endif()

I guess on Ubuntu MSVC is not set therefore, when compiling OpenGV, the flag -march=native is set.

Therefore adding the flag when compiling my code fixed it.

pmoulon commented 7 years ago

Thanks for your detailed answer. I think you can now close the issue.

ckchng commented 4 years ago

@gregyharra you sir have just saved my day!

ckchng commented 4 years ago

By the way, what's the proper solution if I dont want to compile my code with -native?

gregyharra commented 4 years ago

@ckchng I haven't looked into the solution as I didn't have time to analyze the problem in more detail. My guess is that the --march=native flag under ubuntu activates other flags that are not set while compiling the code without it. I guess that you are using Eigen for matrix computations, therefore, the Eigen that you are using doesn't have the same flags that OpenGV uses and thus the Eigen version used will clash.

You can look at the following link to had a look at which flags are set while using the --march=native:

https://stackoverflow.com/questions/5470257/how-to-see-which-flags-march-native-will-activate

If you don't mind adding the different flags that --march=native adds, then I would recommend using it.

A workaround that I just thought is to remove the --march=native flag from OpenGV and then that might work as well, but I am not sure that is a good idea

vladhondru25 commented 4 years ago

@gregyharra After wasting 2 days, you sir have saved my life and my MSc Project.