uhd
uhd copied to clipboard
Crash while unplugging a connected usb device
trafficstars
Issue Description
I would like my application to allow usb usrp devices to be added or removed by the user at runtime. This seems to work, but if I have an active multi_uspr connection the application crashes when the shared_ptr of an unplugged device goes out of scope. (A workaround is to keep a list of invalid pointers...).
Setup Details
Host OS: Ubuntu 22.04 UHD: UHD_4.6.0.0-3-g080b1baa Hardware: USRP B205mini
Expected Behavior
The application should continue to run.
Actual Behaviour
The application crashes with this message:
terminate called after throwing an instance of 'uhd::usb_error'
what(): RuntimeError: USBError -4: usb tx4 submit failed: LIBUSB_ERROR_CODE -4
Steps to reproduce the problem
Just create a multi_usrp connection, unplug the hardware and let the pointer go out of scope.
#include <iostream>
#include <uhd/usrp/multi_usrp.hpp>
int main()
{
uhd::usrp::multi_usrp::sptr dev = uhd::usrp::multi_usrp::make("");
std::cout << "Unplug the device and press enter\n";
std::getchar();
dev = nullptr;
std::cout << "Press enter\n";
std::getchar();
return 0;
}
If you don't unplug the device destructing the pointer does not cause a crash.