IntelRealSense / librealsense

Intel® RealSense™ SDK
https://www.intelrealsense.com/
Apache License 2.0
7.58k stars 4.82k forks source link

The program crashed when calling rs2::motion_frame.get_motion_data() #11014

Closed HEIDIES closed 1 year ago

HEIDIES commented 1 year ago
Required Info
Camera Model D435i
Firmware Version 05.13.00.50
Operating System & Version Ubuntu 18
Kernel Version (Linux Only) 4.9.253
Platform NVIDIA Jetson Xavier NX
SDK Version 2.50.0 }
Language C++

Issue Description

There are two pipelines in the program, which open depth stream and IMU stream respectively. The IMU data is used for subsequent calculations. The program runs well at first, but the program crashed when calling rs2::motion_frame.get_motion_data() after about an hour every time. The main codes are as follows:

cfg.enable_stream(RS2_STREAM_ACCEL, RS2_FORMAT_MOTION_XYZ32F, 250);
cfg.enable_stream(RS2_STREAM_GYRO, RS2_FORMAT_MOTION_XYZ32F, 200);
pipeline.start(cfg, [&](const rs2::frame &frame) {
                            std::lock_guard<std::mutex> lock(pipe_mutex);
                            if (auto mf = frame.as<rs2::motion_frame>()) {
                                if (mf.get_profile().stream_type() == RS2_STREAM_GYRO) {
                                    gyro = mf;
                                    gyro.keep();
                                } else if (mf.get_profile().stream_type() == RS2_STREAM_ACCEL) {
                                    accel = mf;
                                    accel.keep();
                                }
                            }
                        });
...
auto data = accel.get_motion_data(); // program crashed here.
...
MartyG-RealSense commented 1 year ago

Hi @HEIDIES As you are using the Keep() instruction, I would recommend monitoring over a period of time the amount of available remaining memory that your computer has, using an Ubuntu system monitoring tool such as htop. This is because Keep() causes frames to be stored in the computer's memory, so the computer's memory capacity is progressively consumed over time. When available memory falls below a certain level, an application's performance will start to degrade and it will eventually lead to a program freeze or crash.

If the crash occurs within a consistent time frame then that may indicate that memory is being consumed at approximately the same rate each time the program is run, leading to a crash at around the same time duration after starting the program.

You may be able to extend the amount of time that a program using Keep() can run for by periodically releasing frames from the memory. In C++ frames can be released with the rs2_release_frame instruction, such as rs2_release_frame(frame);

MartyG-RealSense commented 1 year ago

Hi @HEIDIES Do you require further assistance with this case, please? Thanks!

MartyG-RealSense commented 1 year ago

Case closed due to no further comments received.