ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Unknowable bug on "ROS_INFO", Bus error and Segmentation fault [closed]

asked 2018-08-20 04:23:19 -0600

harderthan gravatar image

updated 2018-08-20 21:41:15 -0600

Hello, experts. I have a bug on my code.

When it reach functions as ROS_INFO or assignment values, this bug log "Bus error (core dumped)" or "Segmentation fault (core dumped)" or "Aborted (core dumped)".
I want to test it more accurately, but it is not easy to debug because I get an error in one of the thousands of cases in the Bag file.

Briefly, it is a function that it convert points position with matrix. I attached the code.

// Conver a point from a Lidar point to a Image point
void Fusion::Conversion::points2img(const Fusion::Point &_lidar_pt, const cv::Mat &projection_matrix, cv::Point2f &_point){
    cv::Mat pt_3D(4, 1, CV_32FC1);  
    float *pt_3D_data = (float*);  
    pt_3D_data[0] = _lidar_pt.x;  
    pt_3D_data[1] = _lidar_pt.y;  
    pt_3D_data[2] = _lidar_pt.z;  
    pt_3D_data[3] = 1.0f;  
    ROS_INFO("Check Error 0: %f, 1: %f, 2: %f, 4: %f", (float)[0], (float)[1], (float)[2], (float)[3]);  

cv::Mat pt_2D = projection_matrix * pt_3D;  
float *pt_2D_data = (float*);  
ROS_INFO("Check Error 0 1: %f, 1: %f, 2: %f", (float)[0], (float)[1], (float)[2]);  
float w = pt_2D_data[2];  
ROS_INFO("w %f", w);  
float y = pt_2D_data[0] / w;  
ROS_INFO("y %f", y);  
float x = pt_2D_data[1] / w;    
ROS_INFO("x %f", x);   

cv::Point2f result(y, x);  
_point = result;  

The error was caused on float w = pt_2D_data[2]; or float w = pt_2D_data[2]; or other ROS_INFO functions.
Below is the error log.

*** Error in `/PATH/conversion/conversion_points2img_node': corrupted double-linked list: 0x000000000343b2d0 ***
======= Backtrace: =========

gdb debuger log

Thread 1 "conversion_poin" received signal SIGSEGV, Segmentation fault. malloc_consolidate (av=av@entry=0x7ffff59f8b20 <main_arena>) at malloc.c:4167 4167    malloc.c: No such file or directory.

I do not know how to solve this problem. Has anyone experienced a similar problem?

UPDATE: I fixed this problem.

But, I didn't find reason for this ... (more)

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by harderthan
close date 2019-01-31 08:11:11.489750


I can sure about that the type of const Fusion::Point _lidar_pt's member are float.

harderthan gravatar image harderthan  ( 2018-08-20 08:33:08 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-08-20 04:34:10 -0600

updated 2018-08-20 10:22:07 -0600

The problem is this line here:

float pt_3D_data = (float); is a pointer to the start of the data your casting this to a float storing it in a float and then trying to use it as a pointer. This is all over the place and I'm surprised it compiles tbh.

It should be:

float *pt_3D_data =;

EDIT: Okay that's updated now.

I really recommend you use the cv::Mat::at methods to access and update the elements of the cv::Mat object this is exactly what they're for, accessing the data directly and casting pointers all over the place is going to cause you a world of pain.

The data property of the Mat object has a type of uchar* so when you index it with an lvalue using [2] you're adding two bytes to it not (2 * sizeof(float)), you're then casting a non-aligned pointer to a float* which if nothing else if going to give you garbage values. All in all stick to the at methods unless performance is really important to you.

UPDATE: If you really need to access the data directly fair enough, but get the code working correctly with at methods first then optimise the code from this point where you know it's working.

Having said that. The code (float)[2] seems to be attempting to get the 3rd element of a 2 element vector! Which you would expect to crash you code, you seem to have copy and pasted the code to print out the 3D vector without removing the last element.

edit flag offensive delete link more


Hello, @PeteBlackerThe3rd.
Thank for your answer.

First of all, could you check this link.
It show us the way to use with a pointer.

I have a issue about real-time processing. So, I didn't use

harderthan gravatar image harderthan  ( 2018-08-20 08:30:39 -0600 )edit

By the way, I guesss that you maybe looked wrong code.
float *pt_3D_data = (float*); -> float pt_3D_data = (float);

harderthan gravatar image harderthan  ( 2018-08-20 08:30:50 -0600 )edit

I fixed this issue.

harderthan gravatar image harderthan  ( 2018-08-20 21:41:40 -0600 )edit

Question Tools

1 follower


Asked: 2018-08-20 04:23:19 -0600

Seen: 720 times

Last updated: Aug 20 '18