Ask Your Question

Segmentation fault (core dumped)

asked 2018-07-10 07:59:01 -0500

arya gravatar image

updated 2018-07-10 07:59:49 -0500

Hello dears, i would like to simply scan front but i got this error "Segmentation fault (core dumped)" do you know what is the reason or how to fix this? thank you.

double FrontRange(sensor_msgs::LaserScan & LaserScanMsg) {

return LaserScanMsg.ranges[LaserScanMsg.ranges.size()/2]; }

edit retag flag offensive close merge delete



You should print the size of the range before the return to check if the message isn't empty. Maybe you are calling your function too early so the first message hasn't been received yet, so you are sending an empty message (leading to the segfault issue).

Delb gravatar image Delb  ( 2018-07-10 09:40:28 -0500 )edit

Moreover, are you sure the issue comes from this function in particular ?

Delb gravatar image Delb  ( 2018-07-10 09:40:47 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-07-18 03:59:15 -0500

Infection gravatar image

You can first try to check if the message is empty by using LaserScanMsg.ranges.empty(). If this returns a 1, then your message is indeed empty, and any other action you try to do on it will result in a Segmentation Fault.

I would suggest the following:

if( !LaserScanMsg.ranges.empty() ) { return LaserScanMsg.ranges[LaserScanMsg.ranges.size()/2]; }

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-07-10 07:59:01 -0500

Seen: 601 times

Last updated: Jul 18 '18