Ask Your Question
0

Segmentation fault (core dumped)

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

arya gravatar image

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

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

Comments

1

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 imageDelb ( 2018-07-10 09:40:28 -0600 )edit

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

Delb gravatar imageDelb ( 2018-07-10 09:40:47 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

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

2 followers

Stats

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

Seen: 349 times

Last updated: Jul 18 '18