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

Segmentation fault on a Raspberry Pi 4 when recieving a frame inside a ROS service #6366

Closed
immel-f opened this issue May 8, 2020 · 8 comments

Comments

@immel-f
Copy link

immel-f commented May 8, 2020

Required Info
Camera Model D415
Firmware Version (Open RealSense Viewer --> Click info)
Operating System & Version Raspbian Buster
Kernel Version (Linux Only) 4.19.97-v7l+
Platform Raspberry Pi 4
SDK Version 2.3.4 (latest commit)
Language C++
Segment Robot

Issue Description

For a project in ROS I want to implement a service that returns a set number of depth frames from a D415 on a Raspberry Pi 4. Due to the fact that the camera should not be running all the time I planned on directly using the SDK inside the service call to turn the camera on and off. However I recieve a segfault whenever I try to get a frame from the SDK. The code works without problems on a normal computer. This is the relevant bit inside the service function of a minimal working example:

int currentBufferSize_{0}, maxBufferSize_{30};
// Create a Pipeline - this serves as a top-level API for streaming and processing frames
rs2::pipeline p;
// Configure and start the pipeline
rs2::pipeline_profile selection = p.start();
ROS_INFO_STREAM("Pipeline started.");
while (currentBufferSize_ <= maxBufferSize_)
{
// Block program until frames arrive
rs2::frameset frames = p.wait_for_frames(); // <-- segfault occurs here
// Try to get a frame of a depth image
depthImages_.push_back(frames.get_depth_frame());
currentBufferSize_++;
}

I built the SDK on the Pi from source and the examples like rs-callback or rs-hello-world (whose relevant bits are almost the same as the ones here) are working without any problems. According to gdb the segfault occurs somewhere in rs_frame, you can find the output of gdb below. Thank you in advance for your assistance.

    roslaunch depth_image_processing_node_debug.launch
    ... logging to /home/pi/.ros/log/58594abc-90a2-11ea-b42d-dca63240524b/roslaunch-raspberrypi-11662.log
    Checking log directory for disk usage. This may take a while.
    Press Ctrl-C to interrupt
    Done checking log file disk usage. Usage is <1GB.

    started roslaunch server http://192.168.2.109:42369/

    SUMMARY
    ========

    PARAMETERS
    * /pi/depth_image_processing/buffer_size: 100
    * /pi/depth_image_processing/filtering_iterations: 2
    * /pi/depth_image_processing/gaussian_sigma: 3.0
    * /rosdistro: melodic
    * /rosversion: 1.14.4

    NODES
    /pi/
    depth_image_processing (pi_depth_image_processing_ros_tool/depth_image_processing)

    ROS_MASTER_URI=http://localhost:11311

    process[pi/depth_image_processing-1]: started with pid [11683]
    GNU gdb (Raspbian 8.2.1-2) 8.2.1
    Copyright (C) 2018 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    Type "show copying" and "show warranty" for details.
    This GDB was configured as "arm-linux-gnueabihf".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from /home/pi/custom_code_ws/devel/lib/pi_depth_image_processing_ros_tool/depth_image_processing...done.
    Starting program: /home/pi/custom_code_ws/devel/lib/pi_depth_image_processing_ros_tool/depth_image_processing __name:=depth_image_processing __log:=/home/pi/.ros/log/58594abc-90a2-11ea-b42d-dca63240524b/pi-depth_image_processing-1.log
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
    [New Thread 0xb2b023d0 (LWP 11726)]
    [New Thread 0xb21ff3d0 (LWP 11727)]
    [New Thread 0xb19fe3d0 (LWP 11728)]
    [New Thread 0xb0fff3d0 (LWP 11729)]
    [New Thread 0xb05ff3d0 (LWP 11730)]
    [ INFO] [1588894629.308155513]: Launched service: /pi/get_filtered_depth_image
    [ INFO] [1588894629.314638267]: Started '/pi/depth_image_processing' in namespace '/pi'.
    Subscribed topics:
    /tf
    /tf_static
    Advertised topics:
    /rosout
    /tf
    /pi/depth_image_processing/parameter_descriptions
    /pi/depth_image_processing/parameter_updates

    [ INFO] [1588894629.315074538]: Depth image processing node initialized.
    [New Thread 0xaf9ff3d0 (LWP 11874)]
    [New Thread 0xaf1fe3d0 (LWP 11875)]
    [Thread 0xaf1fe3d0 (LWP 11875) exited]
    [New Thread 0xaf1fe3d0 (LWP 11877)]
    [Thread 0xaf1fe3d0 (LWP 11877) exited]
    [New Thread 0xaf1fe3d0 (LWP 11878)]
    [Thread 0xaf1fe3d0 (LWP 11878) exited]
    [New Thread 0xaf1fe3d0 (LWP 11879)]
    [Thread 0xaf1fe3d0 (LWP 11879) exited]
    [New Thread 0xaf1fe3d0 (LWP 11880)]
    [Thread 0xaf1fe3d0 (LWP 11880) exited]
    [New Thread 0xaf1fe3d0 (LWP 11881)]
    [Thread 0xaf1fe3d0 (LWP 11881) exited]
    [New Thread 0xaf1fe3d0 (LWP 11882)]
    [New Thread 0xae9fd3d0 (LWP 11883)]
    [Thread 0xae9fd3d0 (LWP 11883) exited]
    [New Thread 0xae9fd3d0 (LWP 11884)]
    [Thread 0xae9fd3d0 (LWP 11884) exited]
    [New Thread 0xae9fd3d0 (LWP 11886)]
    [Thread 0xae9fd3d0 (LWP 11886) exited]
    [New Thread 0xae9fd3d0 (LWP 11887)]
    [New Thread 0xae1fc3d0 (LWP 11888)]
    [Thread 0xae1fc3d0 (LWP 11888) exited]
    [New Thread 0xae1fc3d0 (LWP 11889)]
    [New Thread 0xad9fb3d0 (LWP 11890)]
    [New Thread 0xad1fa3d0 (LWP 11891)]
    [New Thread 0xac9f93d0 (LWP 11892)]
    [New Thread 0xac1f83d0 (LWP 11893)]
    [Thread 0xac1f83d0 (LWP 11893) exited]
    [New Thread 0xac1f83d0 (LWP 11894)]
    [Thread 0xac1f83d0 (LWP 11894) exited]
    [New Thread 0xac1f83d0 (LWP 11895)]
    [Thread 0xac1f83d0 (LWP 11895) exited]
    [New Thread 0xac1f83d0 (LWP 11896)]
    [Thread 0xac1f83d0 (LWP 11896) exited]
    [New Thread 0xac1f83d0 (LWP 11897)]
    [Thread 0xac1f83d0 (LWP 11897) exited]
    [New Thread 0xab7ff3d0 (LWP 11898)]
    [New Thread 0xaaffe3d0 (LWP 11899)]
    [New Thread 0xaa7fd3d0 (LWP 11900)]
    [New Thread 0xa9ffc3d0 (LWP 11901)]
    [New Thread 0xac1f83d0 (LWP 11902)]
    [Thread 0xac1f83d0 (LWP 11902) exited]
    [New Thread 0xa97fb3d0 (LWP 11903)]
    [Thread 0xa97fb3d0 (LWP 11903) exited]
    [New Thread 0xac1f83d0 (LWP 11904)]
    [Thread 0xac1f83d0 (LWP 11904) exited]
    [New Thread 0xac1f83d0 (LWP 11905)]
    [New Thread 0xa8ffa3d0 (LWP 11906)]
    [New Thread 0xa765b3d0 (LWP 11907)]
    [New Thread 0xa6e5a3d0 (LWP 11908)]
    [New Thread 0xa97fb3d0 (LWP 11909)]
    [New Thread 0xa61103d0 (LWP 11910)]
    [New Thread 0xa49343d0 (LWP 11911)]
    [New Thread 0xa41333d0 (LWP 11912)]
    [ INFO] [1588894778.671388926]: Pipeline started.

    Thread 38 "depth_image_pro" received signal SIGSEGV, Segmentation fault.
    [Switching to Thread 0xa765b3d0 (LWP 11907)]
    0xb6f50f30 in __gnu_cxx::__atomic_add (__mem=0xb564c4dc, __val=1)
    at /usr/include/c++/8/ext/atomicity.h:53
    53	  { __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); }
    (gdb) backtrace
    #0  0xb6f50f30 in __gnu_cxx::__atomic_add (__mem=0xb564c4dc, __val=1)
    at /usr/include/c++/8/ext/atomicity.h:53
    #1  0xb6f51080 in __gnu_cxx::__atomic_add_dispatch (__mem=0xb564c4dc, __val=1)
    at /usr/include/c++/8/ext/atomicity.h:96
    #2  0xb6f64eb8 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)1>::_M_add_ref_copy (this=0xb564c4c0)
    at /usr/include/c++/8/bits/shared_ptr_base.h:139
    #3  0xb6f5e50c in std::__shared_count<(__gnu_cxx::_Lock_policy)1>::operator= (this=0xa765a88c, __r=...)
    at /usr/include/c++/8/bits/shared_ptr_base.h:745
    #4  0xb6f5aec8 in std::__shared_ptr<rs2_stream_profile, (__gnu_cxx::_Lock_policy)1>::operator= (
    this=0xa765a888) at /usr/include/c++/8/bits/shared_ptr_base.h:1078
    #5  0xb6f5af00 in std::shared_ptr<rs2_stream_profile>::operator= (this=0xa765a888)
    at /usr/include/c++/8/bits/shared_ptr.h:103
    #6  0xb6f5af50 in rs2::stream_profile::operator= (this=0xa765a884)
    at /usr/local/include/librealsense2/hpp/rs_frame.hpp:22
    #7  0xb6f5b104 in rs2::frame::frame (this=0xa765a880, other=...)
    at /usr/local/include/librealsense2/hpp/rs_frame.hpp:399
    #8  0xb6f5b6a8 in rs2::frameset::frameset (this=0xa765a880, f=...)
    at /usr/local/include/librealsense2/hpp/rs_frame.hpp:932
    #9  0xb59e0cc0 in rs2::frame::as<rs2::frameset> (this=0xa765a878)
    at /home/pi/librealsense/build/../include/librealsense2/hpp/rs_frame.hpp:573
    #10 librealsense::generic_processing_block::<lambda(rs2::frame, const rs2::frame_source&)>::operator()
    (__closure=0x1b06f4, source=..., f=...) at /home/pi/librealsense/src/proc/synthetic-stream.cpp:73
    #11 rs2::frame_processor_callback<librealsense::generic_processing_block::generic_processing_block(char const*)::<lambda(rs2::frame, const rs2::frame_source&)> >::on_frame(rs2_frame *, rs2_source *) (
    this=0x1b06f0, f=<optimized out>, source=<optimized out>)
    at /home/pi/librealsense/build/../include/librealsense2/hpp/rs_processing.hpp:128
    #12 0xb59ddf0c in librealsense::processing_block::invoke (this=0xa765b890,
    --Type <RET> for more, q to quit, c to continue without paging--
    f=<error reading variable: Cannot access memory at address 0x0>)
    at /home/pi/librealsense/src/proc/synthetic-stream.h:41
    #13 0xb5b57cc8 in librealsense::synthetic_sensor::<lambda(librealsense::frame_holder)>::operator() (
    __closure=<optimized out>, f=...) at /home/pi/librealsense/src/core/streaming.h:138
    #14 librealsense::internal_frame_callback<librealsense::synthetic_sensor::start(librealsense::frame_callback_ptr)::<lambda(librealsense::frame_holder)> >::on_frame(rs2_frame *) (this=<optimized out>,
      fref=<optimized out>) at /home/pi/librealsense/src/types.h:943
        #15 0xb5b66d60 in librealsense::frame_source::invoke_callback (this=0x18ce34, frame=...)
        at /home/pi/librealsense/src/source.cpp:125
        #16 0xb5b4b3c4 in librealsense::uvc_sensor::<lambda(librealsense::platform::stream_profile, librealsense::platform::frame_object, std::function<void()>)>::operator()(librealsense::platform::frame_object, std::function<void()>) (__closure=__closure@entry=0x2e7f88, f=..., continuation=..., p=...)
        at /home/pi/librealsense/src/core/streaming.h:146
        #17 0xb5b4bbe8 in std::_Function_handler<void(librealsense::platform::stream_profile, librealsense::platform::frame_object, std::function<void()>), librealsense::uvc_sensor::open(const stream_profiles&)::<lambda(librealsense::platform::stream_profile, librealsense::platform::frame_object, std::function<void()>)> >::_M_invoke(const std::_Any_data &, librealsense::platform::stream_profile &&, librealsense::platform::frame_object &&, std::function<void()> &&) (__functor=..., __args#0=..., __args#1=..., __args#2=...)
        at /usr/include/c++/8/bits/move.h:182
        #18 0xb5a87f80 in std::function<void (librealsense::platform::stream_profile, librealsense::platform::frame_object, std::function<void ()>)>::operator()(librealsense::platform::stream_profile, librealsense::platform::frame_object, std::function<void ()>) const (__args#2=..., __args#1=..., __args#0=...,
        this=<optimized out>) at /usr/include/c++/8/bits/std_function.h:682
          #19 librealsense::platform::uvc_streamer::<lambda(dispatcher::cancellable_timer)>::operator() (
          __closure=<optimized out>, cancellable_timer=...)
            at /home/pi/librealsense/src/uvc/uvc-streamer.cpp:95
            #20 std::_Function_handler<void(dispatcher::cancellable_timer), librealsense::platform::uvc_streamer::in--Type <RET> for more, q to quit, c to continue without paging--
              it()::<lambda(dispatcher::cancellable_timer)> >::_M_invoke(const std::_Any_data &, dispatcher::cancellable_timer &&) (__functor=..., __args#0=...) at /usr/include/c++/8/bits/std_function.h:297
              #21 0xb5a7abb0 in std::function<void (dispatcher::cancellable_timer)>::operator()(dispatcher::cancellable_timer) const (__args#0=..., this=<optimized out>) at /usr/include/c++/8/bits/std_function.h:682
                #22 active_object<std::function<void (dispatcher::cancellable_timer)> >::do_loop()::{lambda(dispatcher::cancellable_timer)#1}::operator()(dispatcher::cancellable_timer) const (this=<optimized out>, ct=...)
                  at /home/pi/librealsense/src/hid/../concurrency.h:395
                  #23 std::_Function_handler<void (dispatcher::cancellable_timer), active_object<std::function<void (dispatcher::cancellable_timer)> >::do_loop()::{lambda(dispatcher::cancellable_timer)#1}>::_M_invoke(std::_Any_data const&, dispatcher::cancellable_timer&&) (__functor=..., __args#0=...)
                  at /usr/include/c++/8/bits/std_function.h:297
                  #24 0xb5927010 in std::function<void (dispatcher::cancellable_timer)>::operator()(dispatcher::cancellable_timer) const (__args#0=..., this=0xa765ad80) at /usr/include/c++/8/bits/std_function.h:682
                  #25 dispatcher::dispatcher(unsigned int)::{lambda()#1}::operator()() const (__closure=0x2f0f44)
                  at /home/pi/librealsense/src/concurrency.h:231
                  #26 std::__invoke_impl<void, dispatcher::dispatcher(unsigned int)::{lambda()#1}>(std::__invoke_other, dispatcher::dispatcher(unsigned int)::{lambda()#1}&&) (__f=...) at /usr/include/c++/8/bits/invoke.h:60
                  #27 std::__invoke<dispatcher::dispatcher(unsigned int)::{lambda()#1}>(std::__invoke_result&&, (dispatcher::dispatcher(unsigned int)::{lambda()#1}&&)...) (__fn=...) at /usr/include/c++/8/bits/invoke.h:95
                  #28 std::thread::_Invoker<std::tuple<dispatcher::dispatcher(unsigned int)::{lambda()#1}> >::_M_invoke<0u>(std::_Index_tuple<0u>) (this=0x2f0f44) at /usr/include/c++/8/thread:244
                  #29 std::thread::_Invoker<std::tuple<dispatcher::dispatcher(unsigned int)::{lambda()#1}> >::operator()() (this=0x2f0f44) at /usr/include/c++/8/thread:253
                  #30 std::thread::_State_impl<std::thread::_Invoker<std::tuple<dispatcher::dispatcher(unsigned int)::{lambda()#1}> > >::_M_run() (this=0x2f0f40) at /usr/include/c++/8/thread:196
                  #31 0xb551c9b0 in ?? () from /usr/lib/arm-linux-gnueabihf/libstdc++.so.6
                  #32 0xb6698494 in start_thread (arg=0xa765b3d0) at pthread_create.c:486
@MartyG-RealSense
Copy link
Collaborator

Hi @f4b14n1 The first question I would ask in a case involving a segmentation fault is whether you have configured a Swap File on your Pi.

#3341

@immel-f
Copy link
Author

immel-f commented May 8, 2020

Hello @MartyG-RealSense Yes, the Pi has 4 GB of RAM and I have a swap file of 2 GB configured.
image
When running the program the memory usage is around 300 MB.

@MartyG-RealSense
Copy link
Collaborator

Do you have an up to date firmware driver installed inside your camera please? One Pi user with a segmentation fault was able to fix it just by updating the firmware. This can be done through the RealSense Viewer program by going to the 'More' option at the top of the options side-panel and selecting the option from its menu to update to recommended firmware.

@immel-f
Copy link
Author

immel-f commented May 8, 2020

Thank you for your quick response. I updated the camera firmware to version 05.11.06.250, sadly the error still seems to persist.

@MartyG-RealSense
Copy link
Collaborator

It may not make a difference to this particular problem but it is a good idea to use a relatively recent firmware. There has not been a Production firmware for a while, so if you are concerned about having production-level stability, a good rule is to use "one version back" for SDK and firmware. This gives time for any problems in a new version to come to light.

For firmware, the second newest version is currently 5.12.2.100.

@MartyG-RealSense
Copy link
Collaborator

Do you require any further assistance with this case or can it be closed, please? Thanks!

@immel-f
Copy link
Author

immel-f commented May 24, 2020

I updated the firmware version to 5.12.2.100 as mentioned, but the error is still there. I rewrote the problematic bit to use the ros wrapper now, so this issue can be closed. Thanks for your assistance.

@immel-f immel-f closed this as completed May 24, 2020
@MartyG-RealSense
Copy link
Collaborator

I'm pleased that you found a solution that worked for you. Thanks for the update!

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

No branches or pull requests

2 participants