From: Soeren Apel Date: Wed, 24 Oct 2018 20:08:13 +0000 (+0200) Subject: DeviceManager: Prevent PV crashes when scanning for devices X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=528a195cc11e21affe35c923f42893d74031387a;p=pulseview.git DeviceManager: Prevent PV crashes when scanning for devices --- diff --git a/pv/devicemanager.cpp b/pv/devicemanager.cpp index ebf140fd..5090b480 100644 --- a/pv/devicemanager.cpp +++ b/pv/devicemanager.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -252,21 +253,27 @@ DeviceManager::driver_scan( devices_.remove_if([&](shared_ptr device) { return device->hardware_device()->driver() == driver; }); - // Do the scan - auto devices = driver->scan(drvopts); + try { + // Do the scan + auto devices = driver->scan(drvopts); - // Add the scanned devices to the main list, set display names and sort. - for (shared_ptr& device : devices) { - const shared_ptr d( - new devices::HardwareDevice(context_, device)); - driver_devices.push_back(d); - } + // Add the scanned devices to the main list, set display names and sort. + for (shared_ptr& device : devices) { + const shared_ptr d( + new devices::HardwareDevice(context_, device)); + driver_devices.push_back(d); + } - devices_.insert(devices_.end(), driver_devices.begin(), - driver_devices.end()); - devices_.sort(bind(&DeviceManager::compare_devices, this, _1, _2)); - driver_devices.sort(bind( - &DeviceManager::compare_devices, this, _1, _2)); + devices_.insert(devices_.end(), driver_devices.begin(), + driver_devices.end()); + devices_.sort(bind(&DeviceManager::compare_devices, this, _1, _2)); + driver_devices.sort(bind( + &DeviceManager::compare_devices, this, _1, _2)); + + } catch (const sigrok::Error &e) { + qWarning() << QApplication::tr("Error when scanning device driver '%1': %2"). + arg(QString::fromStdString(driver->name()), e.what()); + } return driver_devices; }