Xlink can easily crash due to the newer C++ code within it yet having no exception handling.
For example, the file usb_host.cpp has a lot of C++ code in it and most of it can throw exceptions. However, there is no exception handling in functions, e.g. getUSBDevices(), to prevent their doomed cascade upward into standard-C code...which causes an app crash/segfault. 💥
Since exceptions can be throw by trivial uses like std::string(...) or container::at(), I recommend that the top-level functions in all cpp files be marked noexcept. Then add try/catch to all needed places to catch any exceptions and return relevant error codes instead. All modern editors like vscode and analyzers provide clear feedback of functions marked noexcept yet calling things which can throw.
Setup
- all os, platforms, compilers
- XLink in v2.21.2, master, develop, and for many past versions
Repro
- Edit
usb_host.cpp and insert as the first line of the function getUSBDevices() the following: throw std::runtime_error("crash me");
- config and build. I used VS2019.
- attach a USB oak device
- run
tests/color_camera_node_test
Result
App immediately crashes.
Expected
App somehow gracefully fails, in this case it should report it could find no usb devices.
Xlink can easily crash due to the newer C++ code within it yet having no exception handling.
For example, the file
usb_host.cpphas a lot of C++ code in it and most of it can throw exceptions. However, there is no exception handling in functions, e.g.getUSBDevices(), to prevent their doomed cascade upward into standard-C code...which causes an app crash/segfault. 💥Since exceptions can be throw by trivial uses like
std::string(...)orcontainer::at(), I recommend that the top-level functions in all cpp files be markednoexcept. Then add try/catch to all needed places to catch any exceptions and return relevant error codes instead. All modern editors like vscode and analyzers provide clear feedback of functions marked noexcept yet calling things which can throw.Setup
Repro
usb_host.cppand insert as the first line of the functiongetUSBDevices()the following:throw std::runtime_error("crash me");tests/color_camera_node_testResult
App immediately crashes.
Expected
App somehow gracefully fails, in this case it should report it could find no usb devices.