alejocb / rgbdtam

RGBDTAM: A Cost-Effective and Accurate RGB-D Tracking and Mapping System.
GNU General Public License v3.0
110 stars 50 forks source link

Segmentation fault (core dumped) rosrun rgbdtam rgbdtam #12

Open Mirmix opened 6 years ago

Mirmix commented 6 years ago

While running the code i am getting segmentation fault [core dumped] error. I tried to find the error using gdb .

Thread 27 "rgbdtam" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fff88f29700 (LWP 9148)]
_int_free (av=0x7fff4c000020, p=0x7fff4c0009f0, have_lock=0) at malloc.c:3984
3984    malloc.c: No such file or directory.
(gdb) where
#0  _int_free (av=0x7fff4c000020, p=0x7fff4c0009f0, have_lock=0) at malloc.c:3984
#1  0x00007fffeddaa53c in __GI___libc_free (mem=<optimized out>) at malloc.c:2968
#2  0x00007ffff6a77609 in cv::Mat::deallocate() () from /opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_core3.so.3.3
r#3  0x0000000000452109 in cv::Mat::release (this=0x7fff88f28bd0)
    at /opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2/core/mat.inl.hpp:804
#4  cv::Mat::~Mat (this=0x7fff88f28bd0, __in_chrg=<optimized out>)
    at /opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2/core/mat.inl.hpp:690
#5  0x000000000044391a in get_photometric_errors_matrix_sd_exhaustive ()
    at /home/imfusion/catkin_ws/src/rgbdtam/src/SemiDenseMapping.cpp:1756
#6  0x00007fffee31e9ee in ?? () from /usr/lib/x86_64-linux-gnu/libgomp.so.1
#7  0x00007ffff2a956ba in start_thread (arg=0x7fff88f29700) at pthread_create.c:333
#8  0x00007fffede2d41d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

It seems like that my error is at SemiDenseMapping.cpp:1756.

    cv::Mat interpolated_values_o = cv::Mat::zeros(round(l_end - l_init+30),1,CV_32FC1);

I suspect memory leak as error origin. So for solving the issue I also add this line to free the memory after using it.

interpolated_values_o.release();

But it also did not resolve the problem. After gdb I get the same error but the line was where I was releasing the memory. After surfing on the internet I also found similar problem . I applied their solution which was replacing the line with this :

 cv::Mat interpolated_values_o ;
interpolated_values_o.create(round(l_end - l_init+30),1,CV_32FC1);
interpolated_values_o=cv::Scalar(0);

But it did not also resolve the problem. Error or also may be caused by some kind of race condition. Or maybe heap is corrupted by releasing same memory space more than once.

NikolausDemmel commented 6 years ago

I have the same issue. I'm on Ubuntu 16.04 with ROS's opencv 3. In fact I have this issue with both the master branch and @NH89's ROS-kinetic branch from #7.

I did some digging. It seems the segfault occurs when interpolated_values_o is deconstructed.

I also checked the execution of that function / loop with some printfs. It seems that code is executed maybe around 100times before the crash. Also, at the beginning, the code is executed in parallel in 2 threads (I have checked thread id), which doesn't make any sense to me. Maybe some funny business with OMP?

NH89 commented 6 years ago

Hi all, I haven't had the time to touch this for a while. It did run on the set up that I had at the time. Since then OpenCV 3 has moved on from version 3.1 to 3.4. It is likely that there have been some changes in that time. It may also be that I did not discover every factor for crash free running.

From your descriptions I suspect that there is an issue with finding the correct libraries. If possible, makes sure that you have only one version of OpenCV and ROS. Then run all their tests to verify that all relevant components work. When you have ruled out any problem in your ROS and OpenCV installations, then build rgbdtam with debug flags, and run it with gdb (or your favourite debugger) and step through the code, until you find exactly which call is causing the crash. (I find the debug features in Kdevelop useful for this, other IDE's may have equivalent features.)

You would then need to check the class of function called against the API of the version of OpenCV that you have installed. This is how I discovered exactly what needed changing originally. Those changes were due to the restructuring of OpenCV in the major version change 2->3.

One alternate possibility is that you may need some environment variable set correctly in order for the correct components to be found. This may depend on what ROS catkin or other build files you have sourced.

I hope this helps. Best, Nick

izengpan commented 5 years ago

I have met the same problem... Since it has been a long time, has anybody solved this problem?

VimalVasu commented 3 years ago

Bump^ Has anyone solved this issue?