# Segmentation fault while trying to reconnect to the camera stream

**URL:** <https://community.stereolabs.com/t/segmentation-fault-while-trying-to-reconnect-to-the-camera-stream/8266>\
**Category:** C++\
**Tags:** linux, streaming\
**Created:** [March 5, 2025, 6:34pm UTC](https://community.stereolabs.com/t/segmentation-fault-while-trying-to-reconnect-to-the-camera-stream/8266 "2025-03-05T18:34:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mat198](https://community.stereolabs.com/user_avatar/community.stereolabs.com/mat198/32/1926_2.png) [@Mat198](https://community.stereolabs.com/u/Mat198)\
**Post date:** [March 5, 2025, 6:34pm UTC](https://community.stereolabs.com/t/segmentation-fault-while-trying-to-reconnect-to-the-camera-stream/8266/1 "2025-03-05T18:34:03Z")

</div>

I’m trying to create software that reconnects to the camera when a problem occurs. After some reconnection attempts, I face the following error:

```auto
[New Thread 0x7fffd5e00000 (LWP 359929)]
[New Thread 0x7fffd5400000 (LWP 359930)]
[Streaming] Error: Stream Opening returned TIMEOUT (350)
FAILURE. The function does not perform as expected.
[2025-03-05 18:19:13 UTC][ZED][WARNING] FAILURE in sl::ERROR_CODE sl::Camera::open(sl::InitParameters)
[Streaming] Metadata timeout. the size is equal to -1 instead of 21960. Skipping.
[Thread 0x7fffd5400000 (LWP 359930) exited]
[Thread 0x7fffd5e00000 (LWP 359929) exited]
[2025-03-05 18:19:18 UTC][ZED][INFO] Logging level INFO
[2025-03-05 18:19:18 UTC][ZED][ERROR] [ZED] sl::Camera::Open has not been called, no Camera instance running.
[2025-03-05 18:19:18 UTC][ZED][ERROR] [ZED] sl::Camera::Open has not been called, no Camera instance running.
[Streaming] Warning: Failed to retrieve camera settings from sender
[New Thread 0x7fffd5400000 (LWP 360063)]
[New Thread 0x7fffd5e00000 (LWP 360064)]
[Streaming] Error: Stream Opening returned TIMEOUT (350)
FAILURE. The function does not perform as expected.
[2025-03-05 18:19:29 UTC][ZED][WARNING] FAILURE in sl::ERROR_CODE sl::Camera::open(sl::InitParameters)
[Streaming] Metadata timeout. the size is equal to -1 instead of 21960. Skipping.
[Thread 0x7fffd5e00000 (LWP 360064) exited]

Thread 44 "zed_reconnect_t" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffd5400000 (LWP 360063)]
0x00007fffece1ad20 in main_arena () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) 

```

I made a minimal code to test if I was doing something wrong:

```auto
#include <sl/Camera.hpp>

int main(){

    sl::Camera zed;
    sl::InitParameters initParams;
    initParams.input.setFromStream("192.168.1.15", 30000);
    sl::ERROR_CODE cameraStatus;

    while (true) {
        if (!zed.isOpened()) {
            cameraStatus = zed.open(initParams);
            if (cameraStatus != sl::ERROR_CODE::SUCCESS) {
                std::cout << cameraStatus << ". " << sl::toVerbose(cameraStatus) << "\n";
                std::this_thread::sleep_for(std::chrono::seconds(5));
                continue;
            }
        }

        std::cout << "Camera initialized!\n";

        while (true) {
            cameraStatus = zed.grab();
            if (cameraStatus != sl::ERROR_CODE::SUCCESS) {
                std::cout << cameraStatus << ". " << sl::toVerbose(cameraStatus) << "\n";
                zed.close();
                std::this_thread::sleep_for(std::chrono::seconds(1));
                break;
            }
        }
    }
    return 0;
}

```

I’m using the SDK version 4.2.5.

Any suggestion?

---

<div class="post-metadata">

**Author:** ![Myzhar](https://community.stereolabs.com/user_avatar/community.stereolabs.com/myzhar/32/11_2.png) [@Myzhar](https://community.stereolabs.com/u/Myzhar)\
**Post date:** [March 6, 2025, 4:42pm UTC](https://community.stereolabs.com/t/segmentation-fault-while-trying-to-reconnect-to-the-camera-stream/8266/2 "2025-03-06T16:42:25Z")

</div>

Hi @Mat198  
you do not need this type of code because the camera reconnection is automatically handled by the ZED SDK.

I recommend to set [async\_grab\_camera\_recovery](https://www.stereolabs.com/docs/api/structsl_1_1InitParameters.html#a8110a28bc2df2010f8a0b0bcbc225f90) to true and check for the `grab` function to return `sl::ERROR_CODE::CAMERA_REBOOTING` when a disconnection recover is ongoing.

I advise you to check how this process is handled in the ROS 2 Wrapper as a valid example:

> <https://github.com/stereolabs/zed-ros2-wrapper/blob/master/zed_components/src/zed_camera/src/zed_camera_component.cpp#L6073-L6130>

---

<div class="post-metadata">

**Author:** ![Mat198](https://community.stereolabs.com/user_avatar/community.stereolabs.com/mat198/32/1926_2.png) [@Mat198](https://community.stereolabs.com/u/Mat198)\
**Post date:** [March 6, 2025, 5:54pm UTC](https://community.stereolabs.com/t/segmentation-fault-while-trying-to-reconnect-to-the-camera-stream/8266/3 "2025-03-06T17:54:24Z")

</div>

I knew I was doing something wrong. Thank you!
