Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is there a segmentation fault here? #37

Open
SylarAnh opened this issue Nov 2, 2023 · 6 comments
Open

Why is there a segmentation fault here? #37

SylarAnh opened this issue Nov 2, 2023 · 6 comments

Comments

@SylarAnh
Copy link

SylarAnh commented Nov 2, 2023

Stack trace (most recent call last):
#21 Object "/usr/lib/x86_64-linux-gnu/ld-2.31.so", at 0xffffffffffffffff, in
#20 Object "/home/jcwang/code/ws_di-lui-sam/src/di_lui_sam/cmake-build-debug/devel/lib/multi_proxy/multi_proxy_subMapFusion", at 0x555555600ead, in start
#19 Source "../csu/libc-start.c", line 308, in libc_start_main [0x7ffff45e6082]
#18 Source "/home/jcwang/code/ws_di-lui-sam/src/di_lui_sam/src/subMapFusion.cpp", line 2235, in main [0x555555601305]
2232: std::thread OptThread(&SubMapFusion::globalOptimizationThread, &SubMapF);
2233: std::thread pubLoopThread(&SubMapFusion::publishSCWithCloudThread, &SubMapF);
2234:
>2235: ros::spin();
2236:
2237: pubDesOtherThread.join();
2238: pubMapThread.join();
#17 Object "/opt/ros/noetic/lib/libroscpp.so", at 0x7ffff7f2a21e, in ros::spin()
#16 Object "/opt/ros/noetic/lib/libroscpp.so", at 0x7ffff7f41fce, in ros::SingleThreadedSpinner::spin(ros::CallbackQueue*)
#15 Object "/opt/ros/noetic/lib/libroscpp.so", at 0x7ffff7eee882, in ros::CallbackQueue::callAvailable(ros::WallDuration)
#14 Object "/opt/ros/noetic/lib/libroscpp.so", at 0x7ffff7eed171, in ros::CallbackQueue::callOneCB(ros::CallbackQueue::TLS*)
#13 Object "/opt/ros/noetic/lib/libroscpp.so", at 0x7ffff7f3f138, in ros::SubscriptionQueue::call()
#12 Source "/opt/ros/noetic/include/ros/subscription_callback_helper.h", line 144, in call [0x5555556fe2ca]
141: virtual void call(SubscriptionCallbackHelperCallParams& params)
142: {
143: Event event(params.event, create
);
> 144: callback
(ParameterAdapter

::getParameter(event));
145: }
146:
147: virtual const std::type_info& getTypeInfo()
#11 Source "/usr/include/boost/function/function_template.hpp", line 763, in operator() [0x555555702548]
760: if (this->empty())
761: boost::throw_exception(bad_function_call());
762:
> 763: return get_vtable()->invoker
764: (this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS);
765: }
#10 Source "/usr/include/boost/function/function_template.hpp", line 158, in invoke [0x5555556b57eb]
155: f = reinterpret_cast<FunctionObj*>(function_obj_ptr.data);
156: else
157: f = reinterpret_cast<FunctionObj*>(function_obj_ptr.members.obj_ptr);
> 158: BOOST_FUNCTION_RETURN((f)(BOOST_FUNCTION_ARGS));
159: }
160: };
#9 Source "/usr/include/boost/function/function_template.hpp", line 763, in operator() [0x5555556c1db5]
760: if (this->empty())
761: boost::throw_exception(bad_function_call());
762:
> 763: return get_vtable()->invoker
764: (this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS);
765: }
#8 Source "/usr/include/boost/function/function_template.hpp", line 158, in invoke [0x555555696649]
155: f = reinterpret_cast<FunctionObj
>(function_obj_ptr.data);
156: else
157: f = reinterpret_cast<FunctionObj*>(function_obj_ptr.members.obj_ptr);
> 158: BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
159: }
160: };
#7 Source "/usr/include/boost/bind/bind.hpp", line 1306, in operator()<const boost::shared_ptr<const sensor_msgs::PointCloud2
<std::allocator > >&> [0x5555556a70ac]
1303: template result_type operator()( A1 && a1 )
1304: {
1305: rrlist1< A1 > a( a1 );
>1306: return l_( type<result_type>(), f_, a, 0 );
1307: }
1308:
1309: template result_type operator()( A1 && a1 ) const
#6 Source "/usr/include/boost/bind/bind.hpp", line 319, in operator()<boost::mfi::mf1<void, SubMapFusion, const boost::shared_ptr<const sensor_msgs::PointCloud2<std::allocator > >&>, boost::bi::rrlist1<const boost::shared_ptr<const sensor_msgs::PointCloud2<std::allocator > >&> > [0x5555556b5515]
317: template<class F, class A> void operator()(type, F & f, A & a, int)
318: {
> 319: unwrapper::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]);
320: }
321:
322: template<class F, class A> void operator()(type, F const & f, A & a, int) const
#5 Source "/usr/include/boost/bind/mem_fn_template.hpp", line 165, in operator() [0x5555556c1a47]
163: R operator()(T * p, A1 a1) const
164: {
> 165: BOOST_MEM_FN_RETURN (p->f_)(a1);
166: }
167:
168: template R operator()(U & u, A1 a1) const
#4 Source "/home/jcwang/code/ws_di-lui-sam/src/di_lui_sam/src/subMapFusion.cpp", line 681, in laserCloudInfoHandler [0x55555561e8f4]
679: isKeyframe(context_info);
680: buildFrameList(context_info);
> 681: buildSubmap(context_info);
682: }
683: // std::cout << "laser: finished! " << std::endl;
684: }
#3 Source "/home/jcwang/code/ws_di-lui-sam/src/di_lui_sam/src/subMapFusion.cpp", line 1109, in buildSubmap [0x555555623a08]
1106: _downsize_filtermap.setInputCloud(cloud_in_ego_odom);
1107: _downsize_filtermap.filter(
_cloud_temp);
1108:
>1109: buildiKDTree(_cloud_temp);//////TODO:这里有问题,会重复释放内存
1110: mtx_map.lock();
1111: *_lidarmap_current += *_cloud_temp;
1112: _cloud_temp->clear();
#2 Source "/home/jcwang/code/ws_di-lui-sam/src/di_lui_sam/src/subMapFusion.cpp", line 1164, in buildiKDTree [0x555555624060]
1161: }
1162:
1163: double st_time = omp_get_wtime();
>1164: ikdtree.Add_Points(PointToAdd, true);
1165: double kdtree_incremental_time = omp_get_wtime() - st_time;
1166: }
#1 Source "/home/jcwang/code/ws_di-lui-sam/src/di_lui_sam/third_parties/ikd-Tree/ikd_Tree.cpp", line 501, in Add_Points [0x7ffff72eff4d]
498: mid_point.y = Box_of_Point.vertex_min[1] + (Box_of_Point.vertex_max[1] - Box_of_Point.vertex_min[1]) / 2.0;
499: mid_point.z = Box_of_Point.vertex_min[2] + (Box_of_Point.vertex_max[2] - Box_of_Point.vertex_min[2]) / 2.0;
500: PointVector().swap(Downsample_Storage);
> 501: Search_by_range(Root_Node, Box_of_Point, Downsample_Storage);
502: min_dist = calc_dist(PointToAdd[i], mid_point);
503: downsample_result = PointToAdd[i];
504: for (int index = 0; index < Downsample_Storage.size(); index++)
#0 Source "/home/jcwang/code/ws_di-lui-sam/src/di_lui_sam/third_parties/ikd-Tree/ikd_Tree.cpp", line 1268, in Search_by_range [0x7ffff72ecce4]
1265: if (!root->point_deleted)
1266: Storage.push_back(root->point);
1267: }
>1268: if ((Rebuild_Ptr == nullptr) || root->left_son_ptr != *Rebuild_Ptr)
1269: {
1270: Search_by_range(root->left_son_ptr, boxpoint, Storage);
1271: }
Segmentation fault (Address not mapped to object [(nil)])
E07EzurTRZ
Ft2pPmFYZT

@FPSE12
Copy link

FPSE12 commented Nov 6, 2023

I have the same issue, I got a "segment fault" when I use the "Add_Points" function.
2023-11-06 10-45-01 的屏幕截图
2023-11-06 10-46-29 的屏幕截图

@ludovicoruga
Copy link

I am also experiencing the same issue:
image
image

Any support would be greatly appreciated!

@ludovicoruga
Copy link

I noticed that if I set the value if 'Minimal_Unbalanced_Tree_Size' to INIFINITY in ikd_tree.h, the segmentation fault error stops happening. I think this could indicate an issue with the re-building process in the second thread.
This is not a viable solution since when the tree size increases, the computation time increases exponentially, but could give an idea on where to look for to fix the issue.

I hope this can be useful!

@ning-zelin
Copy link

rebuild thread: write Rebuild_Ptr:
image
add points thread: read Rebuild_Ptr:
image
This variable was read and written without mutex, leading to a segmentation fault. This is merely my initial hypothesis and has yet to be confirmed.

@XYudong
Copy link

XYudong commented Jul 20, 2024

Experiencing the same issue here. Having the same hypothesis as what @ning-zelin mentioned.
A temporary workaround could be:

  1. comment out the code creating the rebuild_thread to disable multi-threading for rebuild;
  2. adjust Rebuild() method to always use the plain rebuild pipeline;

which seems work for me currently.

@supersupercoconut
Copy link

Experiencing the same issue here. Having the same hypothesis as what @ning-zelin mentioned. A temporary workaround could be:

  1. comment out the code creating the rebuild_thread to disable multi-threading for rebuild;
  2. adjust Rebuild() method to always use the plain rebuild pipeline;

which seems work for me currently.
Thanks!! I commeted out the pthread_create( &rebuild_thread, NULL, multi_thread_ptr, ( void * ) this ); Its works now !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants